최신판 |
당신의 편집 |
1번째 줄: |
1번째 줄: |
| {{소문자}} | | {{소문자}} |
| ==개요==
| | ;cron |
| ;cron, cronie, crond, cron daemon, crontab, cron job, crontab job | | ;크론, 크론탭, 리눅스 작업 스케줄러 |
| ;크론, 크론 데몬, 크론탭, 크론작업, 리눅스 작업 스케줄러 | |
| ;/usr/sbin/crond
| |
| ;/usr/bin/crontab
| |
| * 프로세스 예약 데몬
| |
| * 리눅스용 작업 스케줄러
| |
| * 특정시각에 명령어가 수행되도록 등록가능
| |
| * cronie(패키지) = crond([[데몬]]) + crontab(크론 계획표<ref>크론 테이블(cron table)</ref>)
| |
| * 로그: [[/var/log/cron]]에 변경/수행 이력이 기록됨
| |
| * 런레벨, 사용자 권한 등 환경에 따라 GUI 프로그램을 실행시키거나 X윈도우에서 별도의 창을 띄우는 작업은 불가능할 수 있음
| |
|
| |
|
| ==등록형식==
| | * * * * * 실행할 명령어 |
| <syntaxhighlight lang='text'>
| | ┬ ┬ ┬ ┬ ┬ |
| * * * * * 수행할 명령어 | | │ │ │ │ │ |
| ┬ ┬ ┬ ┬ ┬ | | │ │ │ │ │ |
| │ │ │ │ │ | | │ │ │ │ └───── 요일 (0 - 6) (0 =일요일) |
| │ │ │ │ │ | | │ │ │ └────────── 월 (1 - 12) |
| │ │ │ │ └───────── 요일 (0 - 6) (0:일요일, 1:월요일, 2:화요일, …, 6:토요일) | | │ │ └─────────────── 일 (1 - 31) |
| │ │ │ └───────── 월 (1 - 12) | | │ └──────────────────── 시 (0 - 23) |
| │ │ └───────── 일 (1 - 31) | | └───────────────────────── 분 (0 - 59) |
| │ └───────── 시 (0 - 23) | |
| └───────── 분 (0 - 59)
| |
| </syntaxhighlight>
| |
| :→ "분시일월요"
| |
|
| |
|
| ==예시==
| | :→ 분시일월요! |
| <syntaxhighlight lang='text'>
| |
| * * * * * /root/every_1min.sh
| |
| </syntaxhighlight>
| |
| :→ 매 1분마다 /root/every_1min.sh 를 수행 (하루에 1440회<ref>24시간×60회</ref>) | |
| <syntaxhighlight lang='text'>
| |
| 15,45 * * * * /root/every_30min.sh
| |
| </syntaxhighlight>
| |
| :→ 매시 15분, 45분에 /root/every_30min.sh 를 수행 (하루에 48회<ref>24시간×2회</ref>)
| |
| <syntaxhighlight lang='text'>
| |
| */10 * * * * /root/every_10min.sh
| |
| </syntaxhighlight>
| |
| :→ 10분마다 /root/every_10min.sh 를 수행 (하루에 144회<ref>24시간×6회</ref>)
| |
| <syntaxhighlight lang='text'>
| |
| 0 2 * * * /root/backup.sh
| |
| </syntaxhighlight>
| |
| :→ 매일 02:00에/root/backup.sh 를 수행 (하루에 1회)
| |
| <syntaxhighlight lang='text'>
| |
| 30 */6 * * * /root/every_6hours.sh
| |
| </syntaxhighlight>
| |
| :→ 매 6시간마다 수행(00:30, 06:30, 12:30, 18:30)
| |
| <syntaxhighlight lang='text'>
| |
| 30 1-23/6 * * * /root/every_6hours.sh
| |
| </syntaxhighlight>
| |
| :→ 1시부터 매 6시간마다 수행(01:30, 07:30, 13:30, 19:30)
| |
| <syntaxhighlight lang='text'>
| |
| 0 8 * * 1-5 /root/weekday.sh
| |
| </syntaxhighlight>
| |
| :→ 평일(월요일~금요일) 08:00
| |
| <syntaxhighlight lang='text'>
| |
| 0 8 * * 0,6 /root/weekend.sh
| |
| </syntaxhighlight>
| |
| :→ 주말(일요일, 토요일) 08:00
| |
|
| |
|
| ==작업목록 확인== | | ==작업 목록 확인== |
| {{참고|crontab 작업 목록 전체 보기}} | | {{참고|crontab 작업 목록 전체 보기}} |
| {{소스헤더|현재 사용자}}
| | ;현재 사용자 |
| <syntaxhighlight lang='console'> | | <source lang='dos'> |
| [root@zetawiki ~]# crontab -l | | [root@jmnote ~]# crontab -l |
| no crontab for root | | no crontab for root |
| </syntaxhighlight> | | </source> |
|
| |
|
| {{소스헤더|다른 사용자}}
| | ;다른 사용자 |
| <syntaxhighlight lang='console'> | | <source lang='dos'> |
| [root@zetawiki ~]# crontab -l -u testuser | | [root@jmnote ~]# crontab -l -u testuser |
| no crontab for testuser | | no crontab for testuser |
| </syntaxhighlight> | | </source> |
|
| |
|
| ==수동 등록 ★== | | ==작업 확인/등록/수정== |
| <syntaxhighlight lang='bash'> | | <source lang='dos'> |
| crontab -e | | crontab -e |
| </syntaxhighlight> | | </source> |
| [[vi 편집기]]나 [[Nano 에디터]]로 현재 사용자에 대한 cron작업의 확인/수정을 직접 할 수 있다.
| | vi 편집기로서 현재 사용자에 대한 cron작업의 확인/수정을 할 수 있다. |
|
| |
|
| ==등록 스크립트== | | ==예약작업 등록== |
| {{참고|스크립트 crontab 등록}}
| | ;명령어 (예시) |
| | <source lang='bash'> |
| | cat <(crontab -l) <(echo "1 5 * * * /root/myscript.sh") | crontab - |
| | </source> |
| | :→ 매일 5시 1분에 /root/myscript.sh 를 수행하도록 등록 |
|
| |
|
| ==삭제==
| | ;실행예시 |
| 현재 사용자의 예약작업을 모두 삭제
| | <source lang='dos'> |
| <syntaxhighlight lang='bash'>
| | [root@jmnote ~]# crontab -l |
| crontab -r
| |
| </syntaxhighlight>
| |
| | |
| {{소스헤더|실행예시}}
| |
| <syntaxhighlight lang='console'> | |
| [root@zetawiki ~]# crontab -l | |
| * * * * * /root/a.sh
| |
| * * * * * /root/b.sh
| |
| * * * * * /root/c.sh
| |
| [root@zetawiki ~]# crontab -r
| |
| [root@zetawiki ~]# crontab -l
| |
| no crontab for root | | no crontab for root |
| </syntaxhighlight> | | [root@jmnote ~]# cat <(crontab -l) <(echo "1 5 * * * /root/myscript.sh") | crontab - |
| | | [root@jmnote ~]# crontab -l |
| ==연습과제==
| | 1 5 * * * /root/myscript.sh |
| * [[1분마다 "Hello World" hello.txt 파일에 기록하기]]
| | </source> |
| * [[1분마다 "Hello World - 현재시각" greet.txt 파일에 기록하기]] | |
| * [[2분마다 "Hello World - 현재시각" greet.txt 파일에 기록하기]]
| |
|
| |
|
| ==같이 보기== | | ==같이 보기== |
| * [[작업 스케줄러]] | | *[[작업 스케줄러]] |
| * [[/var/log/cron]] | | *[[crontab 작업 목록 전체 보기]] |
| * [[크론 로그 확인]]
| | *[[/etc/crontab 기본값]] |
| * [[PHP 배치 작업]]
| |
| * [[아나크론 anacron]]
| |
| * [[/etc/crontab 기본값]] | |
| * [[쿠버네티스 CronJob]]
| |
| * [[미디어위키 봇 자동화]]
| |
| * [[크론탭 작업 디렉토리]]
| |
| * [[리눅스 재부팅 예약작업]]
| |
| * [[crontab 홀수 짝수 시각]]
| |
| * [[리눅스 1회성 예약작업 at]]
| |
| * [[크론탭 작업 N분마다 수행]]
| |
| * [[스크립트에서 crontab 수정]]
| |
| * [[crontab 작업 목록 전체 보기]]
| |
| * [[cron.allow, cron.deny]]
| |
|
| |
|
| ==참고== | | ==참고 자료== |
| *http://en.wikipedia.org/wiki/Cron | | *http://en.wikipedia.org/wiki/Cron |
|
| |
|
| [[분류:/usr/bin]] | | [[분류: 리눅스]] |
| [[분류:/usr/sbin]]
| |
| [[분류: cron]]
| |