본문 바로가기

리눅스/강의

[13. 스케쥴러]

crontab


설명

명령/실행을 주기적으로 하기 위한 일종의 스케쥴러 명령어.


명령어

crontab [명령어]

crontab 파일명


[명령어]


데몬 관련

① crontab 실행 확인

[root@localhost test]# ps -ef | grep cron

root       2238      1  0 10:37 ?        00:00:00 crond

root       6314   2927  0 21:26 pts/1    00:00:00 grep cron


② crontab 실행

[root@localhost test]# /etc/init.d/crond start

crond (을)를 시작 중:                                      [  OK  ]


③ crontab 종료

[root@localhost test]# /etc/init.d/crond stop

crond 를 정지 중:                                          [  OK  ]


④ crontab 재시작
[root@localhost test]# /etc/init.d/crond restart
crond 를 정지 중:                                          [  OK  ]
crond (을)를 시작 중:                                      [  OK  ]

⑤ crontab 설정
[root@localhost test]# vim /etc/crontab 

⑥ 일반 사용자에게 crontab 명령어 사용하도록 설정 허가
[root@localhost test]# vim /etc/cron.allow <- ID 등록

명령어 시간

기본구조 : [분] [시] [일] [월] [요일] [command]

[분] : 0~59

[시] : 0~23

[일] : 1~31

[월] : 1~12

[요일] : 0~6 (0부터 시작 = 일요일)

[command] : 실행할 명령어나 스크립트


이론 실습

1) 매주 일요일 마다 pwd 명령어를 실행.

* * * * 0 pwd


2) 매일 1시 0분 마다 pwd 명령어를 실행.

0 1 * * * pwd


3) 매월 1,3,5일 12시 30분 마다 pwd 명령어를 실행.

30 12 1,3,5 * * pwd


4) 매 3월 5,20일은 2시간 간격으로 pwd 명령어를 실행.

* */2 5,20 3 *


5) 매 12월 7,14,21일은 매시간 5분부터 20분까지 pwd 명령어를 실행.

5-20 * 7,14,21 12 *


실제 실습

1) 매주 금요일 오후1시 10분에 rdate를 사용하여 시간동기화를 한 뒤 date 명령어로 시간 확인 후 time 파일에 기록

[root@localhost test]# crontab -e

#분 시 일 월 요일  [명령어]

10 1  *  *  5 rdate -s time.bora.net && date >> time.txt


[root@localhost test]# crontab -l
#분 시 일 월 요일  [명령어]
10 1  *  *  5 rdate -s time.bora.net && date >> time.txt

crontab 스케쥴러로 인해 위와 같은 작업이 예약되어 있는 것을 확인.


'리눅스 > 강의' 카테고리의 다른 글

[15. 프로세스]  (0) 2017.11.05
[14. LVM]  (0) 2017.11.05
[12. 마운트]  (0) 2017.11.02
[11. 파티션]  (0) 2017.11.01
[10. 특수 권한]  (3) 2017.10.12