카테고리 없음

[linux] crontab

냐옴 2021. 3. 1. 02:42
crontab 명령어
# crontab 리스트 보기
$ crontab -l

# crontab 등록
$ crontab -e

# crontab 삭제
$ crontab -r
myjob.sh 스크립트 생성
## ~/myjob.sh 스크립트 생성
$ vi myjob.sh
#!/bin/bash
date >> time.txt
echo date

## myjob.sh 실행 권한 확인
$ chmod +x myjob.sh
$ ll
-rwxr-xr-x myjob.sh
crontab 에 스케줄 등록
$ crontab -e
# 분 시 일 월 주 실행할스크립트 2>&1(에러를 스탠다드 아웃으로 출력)
* * * * * ~/myjob.sh >> myjob.log 2>&1
vi /etc/crontab
# 분 minute (0-59) 
# 시 hour (0-23) 
# 일 day of month (1-31) 
# 월 month (1-12) 
# 주 day of week (0-6) (Sunday=0 or 7) or sun,mon,the,wed,thu,fri,sat 
* * * * * user-name command to be executed
cron expression example
* * * * *	# every minute
0 0 * * * 	# 매일 자정
0 3 * * * 	# 매일 새벽 3시
0 8 * * 1	# 매주 월요일 오전 8시
0 0 1 * *	# 매월 1일
/etc/cron.*
cd /etc/cron.d
cd /etc/cron.daily
cd /etc/cron.hourly
cd /etc/cron.monthly
cd /etc/cron.weekly
crond 서비스
sudo systemctl status crond 
sudo systemctl start crond
sudo systemctl stop crond
sudo systemctl restart crond
cron expression test

https://crontab.guru/

 

Crontab.guru - The cron schedule expression editor

loading... Cron job failures can be disastrous! We created Cronitor because cron itself can't alert you if your jobs fail or never start. Cronitor is easy to integrate and provides you with instant alerts when things go wrong. Learn more about cron job mon

crontab.guru