1. 程式人生 > >shell指令碼使用crontab做定時執行

shell指令碼使用crontab做定時執行

1、編寫指令碼:

#!/bin/bash
if [ ! -f "/home/hadoop/shell/crontab/test" ]; then
echo "test檔案不存在"
touch /home/hadoop/shell/crontab/test
else
echo “刪除test檔案”
rm -rf /home/hadoop/shell/crontab/test
fi
 
echo `date`
echo "hello crontab"

2、編輯/etc/crontab 檔案

備註:注意時間  和檔案路徑

3、坐等到時更新即可

備註:檢視crontab的日誌記錄: 地址:tail -f /var/log/cron

報錯備註:

由於沒有後面紅色的框起來的內容,若有會報錯 【mail】字元報錯  所以建議儲存後面的輸出地址