crontab


代表意義
分鐘
小時
日期
月份
指令
數字範圍
0-59
0-23
1-31
1-12
0-7
commant


*/8 * * * * /usr/bin/python3.6 /home/admin/Simon/MailToLine/mail_db_line.py > /var/log/myjob.log

crontab -l # 顯示內容
crontab -r # 全部清除
crontab [-u -root_or_someone] -e

'''
# SHELL=/bin/bash
# PATH=/sbin:/bin:/usr/sbin:/usr/bin
# HOME=/home/admin
MAILTO=""
cdate=date +%Y-%m-%d
ctime=date +%H:%M:%S

30 6,12 * * * cp -Rf /git_repo/ /mnt/git_backup/ && echo -n $($cdate) $($ctime) &> /mnt/git_backup/latest\ update.txt
'''

# 或者直接以下 [ 2> /dev/null ]
(crontab -l ; echo "* * * * * touch 1.txt") 2> /dev/null | crontab -
# 移除某排程
crontab -l | grep -v touch | crontab -
# 或直接丟入系統排程資料夾內
/etc/cron.hourly 為每小時的01分時執行
/etc/cron.daily 為每天4點02分執行
/etc/cron.weekly 為每星期日4點22分執行
/etc/cron.monthly為每月1號的4點42分執行