뒤로가기

ubuntu cron

설치

# cron 설치
sudo apt update -y
sudo apt install -y cron

# cron 시작
sudo service cron start

실행

crontab -e # 크론탭 설정
crontab -l # 어떤 내용이 들어있는지 확인(크론탭 리스트 확인)
crontab -r # 크론탭 지우기
service cron start # 크론탭 실행

설정

1. 매분마다 실행

# 매분 test.sh 실행
* * * * * /home/script/test.sh
 

2. 특정 시간 마다 실행

# 매주 금요일 오전 5시 45분에 test.sh 를 실행
45 5 * * 5 /home/script/test.sh

# 매일 1시(새벽) test.sh 실행
0 1 * * * /home/script/test.sh

# 매일 매시간 0분, 20분, 40분에 test.sh 를 실행
0,20,40 * * * * /home/script/test.sh
 

3. 범위 실행

# 매일 1시 0분부터 30분까지 매분 tesh.sh 를 실행
0-30 1 * * * /home/script/test.sh
 

4. 간격을 두고 실행

# 매 10분마다 test.sh 를 실행
*/10 * * * * /home/script/test.sh
 

5. 조금 복잡하게 실행

# 5일에서 6일까지 2시,3시,4시에 매 10분마다 test.sh 를 실행
*/10 2,3,4 5-6 * * /home/script/test.sh