原來一直記錯(cuò)了,今天又重新學(xué)習(xí)了一遍
| | | | | |
| | | | | + year [optional]
| | | | +----- day of week (0 - 7) (Sunday=0 or 7)
| | | +---------- month (1 - 12)
| | +--------------- day of month (1 - 31)
| +-------------------- hour (0 - 23)
+------------------------- min (0 - 59)
具體例子大家網(wǎng)上找,推薦一個(gè)crontab 的計(jì)算網(wǎng)站,在線工具
如何實(shí)現(xiàn)每隔5天執(zhí)行腳本.
**注意: **
0 0 */5 * * * 這個(gè)是錯(cuò)誤的!!!
0 0 */5 * * * 這個(gè)是錯(cuò)誤的!!!
0 0 */5 * * * 這個(gè)是錯(cuò)誤的!!!
重要的事情說三遍....
方法1:
自己創(chuàng)建一個(gè)文件,每天執(zhí)行一次腳本,然后計(jì)算天數(shù).當(dāng)count>5 的時(shí)候,說明是第5天,可以執(zhí)行腳本,然后重置時(shí)間.
count=$(cat counter_file)
count=$((count+1))
if [ $count -ge 5 ]
then
do stuff here / call another script
count=0
fi
echo $count >counter_file
方法2:
通過date --utc --date "$1" +%s
來獲得今天(不是當(dāng)前時(shí)間,是00:00:00)距離1970年的秒數(shù),然后除以3600 再除以24 獲得天數(shù),然后取5的余數(shù).
為0的話,說明正好過了5天,可以在腳本開始加入這個(gè)邏輯,然后腳本在crontab中每天執(zhí)行判斷一次.
0 0 1 * * *
每天 的00:00:00執(zhí)行命令