"스크립트 crontab 수정"의 두 판 사이의 차이

잔글 (Jmnote 사용자가 스크립트에서 crontab 수정 문서를 스크립트 crontab 수정 문서로 옮겼습니다)
3번째 줄: 3번째 줄:
*[[crontab -e]] 명령어를 사용하면 수동으로 수정할 수 있다.
*[[crontab -e]] 명령어를 사용하면 수동으로 수정할 수 있다.
*여기서는 수작업 없이 스크립트에서 수정하는 방법을 알아 본다.
*여기서는 수작업 없이 스크립트에서 수정하는 방법을 알아 본다.
*crontab은 표준 입력이 들어오면 전체 내용을 다시 쓴다.


==전체 새로 등록==
==방법 1: 명령어 추가==
*crontab은 표준 입력이 들어오면 전체 내용을 다시 쓴다.
;명령어 (예시)
<source lang='bash'>
cat <(crontab -l) <(echo "1 5 * * * /root/myscript.sh") | crontab -
</source>
:→ 매일 5시 1분에 /root/myscript.sh 를 수행하도록 등록
 
;실행예시
<source lang='dos'>
[root@jmnote ~]# crontab -l
no crontab for root
[root@jmnote ~]# cat <(crontab -l) <(echo "1 5 * * * /root/myscript.sh") | crontab -
[root@jmnote ~]# crontab -l
1 5 * * * /root/myscript.sh
</source>
 
 
==방법 2: 전체 새로 등록==
;명령어 예시
<source lang='bash'>
<source lang='bash'>
echo -e "* * * * * 명령어1\n* * * * * 명령어2" | crontab
echo -e "* * * * * 명령어1\n* * * * * 명령어2" | crontab

2014년 7월 14일 (월) 14:57 판

1 개요

스크립트에서 crontab 수정
  • crontab -e 명령어를 사용하면 수동으로 수정할 수 있다.
  • 여기서는 수작업 없이 스크립트에서 수정하는 방법을 알아 본다.
  • crontab은 표준 입력이 들어오면 전체 내용을 다시 쓴다.

2 방법 1: 명령어 추가

명령어 (예시)
cat <(crontab -l) <(echo "1 5 * * * /root/myscript.sh") | crontab -
→ 매일 5시 1분에 /root/myscript.sh 를 수행하도록 등록
실행예시
[root@jmnote ~]# crontab -l
no crontab for root
[root@jmnote ~]# cat <(crontab -l) <(echo "1 5 * * * /root/myscript.sh") | crontab -
[root@jmnote ~]# crontab -l
1 5 * * * /root/myscript.sh


3 방법 2: 전체 새로 등록

명령어 예시
echo -e "* * * * * 명령어1\n* * * * * 명령어2" | crontab
[root@localhost ~]# crontab -l
no crontab for root
[root@localhost ~]# echo -e "* * * * * /root/every_1min.sh\n15,45 * * * * /root/every_30min.sh"
* * * * * /root/every_1min.sh
15,45 * * * * /root/every_30min.sh
[root@localhost ~]# echo -e "* * * * * /root/every_1min.sh\n15,45 * * * * /root/every_30min.sh" | crontab
[root@localhost ~]# crontab -l
* * * * * /root/every_1min.sh
15,45 * * * * /root/every_30min.sh

4 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}