리눅스 반복 예약작업 cron, crond, crontab 편집하기

경고: 로그인하지 않았습니다. 편집을 하면 IP 주소가 공개되게 됩니다. 로그인하거나 계정을 생성하면 편집자가 사용자 이름으로 기록되고, 다른 장점도 있습니다.

편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.

최신판 당신의 편집
13번째 줄: 13번째 줄:


==등록형식==
==등록형식==
<syntaxhighlight lang='text'>
<source lang='text'>
* * * * *  수행할 명령어
* * * * *  수행할 명령어
┬ ┬ ┬ ┬ ┬
┬ ┬ ┬ ┬ ┬
23번째 줄: 23번째 줄:
│ └───────── 시 (0 - 23)
│ └───────── 시 (0 - 23)
└───────── 분 (0 - 59)
└───────── 분 (0 - 59)
</syntaxhighlight>
</source>
:→ "분시일월요"
:→ "분시일월요"


==예시==
==예시==
<syntaxhighlight lang='text'>
<source lang='text'>
* * * * * /root/every_1min.sh
* * * * * /root/every_1min.sh
</syntaxhighlight>
</source>
:→ 매 1분마다 /root/every_1min.sh 를 수행 (하루에 1440회<ref>24시간×60회</ref>)
:→ 매 1분마다 /root/every_1min.sh 를 수행 (하루에 1440회<ref>24시간×60회</ref>)
<syntaxhighlight lang='text'>
<source lang='text'>
15,45 * * * * /root/every_30min.sh
15,45 * * * * /root/every_30min.sh
</syntaxhighlight>
</source>
:→ 매시 15분, 45분에 /root/every_30min.sh 를 수행 (하루에 48회<ref>24시간×2회</ref>)
:→ 매시 15분, 45분에 /root/every_30min.sh 를 수행 (하루에 48회<ref>24시간×2회</ref>)
<syntaxhighlight lang='text'>
<source lang='text'>
*/10 * * * * /root/every_10min.sh
*/10 * * * * /root/every_10min.sh
</syntaxhighlight>
</source>
:→ 10분마다 /root/every_10min.sh 를 수행 (하루에 144회<ref>24시간×6회</ref>)
:→ 10분마다 /root/every_10min.sh 를 수행 (하루에 144회<ref>24시간×6회</ref>)
<syntaxhighlight lang='text'>
<source lang='text'>
0 2 * * * /root/backup.sh
0 2 * * * /root/backup.sh
</syntaxhighlight>
</source>
:→ 매일 02:00에/root/backup.sh 를 수행 (하루에 1회)
:→ 매일 02:00에/root/backup.sh 를 수행 (하루에 1회)
<syntaxhighlight lang='text'>
<source lang='text'>
30 */6 * * * /root/every_6hours.sh
30 */6 * * * /root/every_6hours.sh
</syntaxhighlight>
</source>
:→ 매 6시간마다 수행(00:30, 06:30, 12:30, 18:30)
:→ 매 6시간마다 수행(00:30, 06:30, 12:30, 18:30)
<syntaxhighlight lang='text'>
<source lang='text'>
30 1-23/6 * * * /root/every_6hours.sh
30 1-23/6 * * * /root/every_6hours.sh
</syntaxhighlight>
</source>
:→ 1시부터 매 6시간마다 수행(01:30, 07:30, 13:30, 19:30)
:→ 1시부터 매 6시간마다 수행(01:30, 07:30, 13:30, 19:30)
<syntaxhighlight lang='text'>
<source lang='text'>
0 8 * * 1-5 /root/weekday.sh
0 8 * * 1-5 /root/weekday.sh
</syntaxhighlight>
</source>
:→ 평일(월요일~금요일) 08:00
:→ 평일(월요일~금요일) 08:00
<syntaxhighlight lang='text'>
<source lang='text'>
0 8 * * 0,6 /root/weekend.sh
0 8 * * 0,6 /root/weekend.sh
</syntaxhighlight>
</source>
:→ 주말(일요일, 토요일) 08:00
:→ 주말(일요일, 토요일) 08:00


63번째 줄: 63번째 줄:
{{참고|crontab 작업 목록 전체 보기}}
{{참고|crontab 작업 목록 전체 보기}}
{{소스헤더|현재 사용자}}
{{소스헤더|현재 사용자}}
<syntaxhighlight lang='console'>
<source lang='console'>
[root@zetawiki ~]# crontab -l
[root@zetawiki ~]# crontab -l
no crontab for root
no crontab for root
</syntaxhighlight>
</source>


{{소스헤더|다른 사용자}}
{{소스헤더|다른 사용자}}
<syntaxhighlight lang='console'>
<source lang='console'>
[root@zetawiki ~]# crontab -l -u testuser
[root@zetawiki ~]# crontab -l -u testuser
no crontab for testuser
no crontab for testuser
</syntaxhighlight>
</source>


==수동 등록 ★==
==수동 등록 ★==
<syntaxhighlight lang='bash'>
<source lang='bash'>
crontab -e
crontab -e
</syntaxhighlight>
</source>
[[vi 편집기]]나 [[Nano 에디터]]로 현재 사용자에 대한 cron작업의 확인/수정을 직접 할 수 있다.
[[vi 편집기]]나 [[Nano 에디터]]로 현재 사용자에 대한 cron작업의 확인/수정을 직접 할 수 있다.


85번째 줄: 85번째 줄:
==삭제==
==삭제==
현재 사용자의 예약작업을 모두 삭제
현재 사용자의 예약작업을 모두 삭제
<syntaxhighlight lang='bash'>
<source lang='bash'>
crontab -r
crontab -r
</syntaxhighlight>
</source>


{{소스헤더|실행예시}}
{{소스헤더|실행예시}}
<syntaxhighlight lang='console'>
<source lang='console'>
[root@zetawiki ~]# crontab -l
[root@zetawiki ~]# crontab -l
* * * * * /root/a.sh
* * * * * /root/a.sh
98번째 줄: 98번째 줄:
[root@zetawiki ~]# crontab -l
[root@zetawiki ~]# crontab -l
no crontab for root
no crontab for root
</syntaxhighlight>
</source>


==연습과제==
==연습과제==

제타위키에서의 모든 기여는 크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0 라이선스로 배포된다는 점을 유의해 주세요(자세한 내용에 대해서는 제타위키:저작권 문서를 읽어주세요). 만약 여기에 동의하지 않는다면 문서를 저장하지 말아 주세요.
또한, 직접 작성했거나 퍼블릭 도메인과 같은 자유 문서에서 가져왔다는 것을 보증해야 합니다. 저작권이 있는 내용을 허가 없이 저장하지 마세요!

취소 편집 도움말 (새 창에서 열림)

이 문서에서 사용한 틀: