定時任務啓動的shell 腳本,腳本內部使用絕對路徑
#!/bin/bash
# Minutes, hour, day, month, week,Use the absolute path
1 4 * * * /home/zhang/script/testCase/uu/start.sh
25 4 * * * /home/zhang/script/testCase/mobile/start.sh
50 4 * * * /home/zhang/script/testCase/union/start.sh
結果是shell腳本輸出爲空,但是當我單獨啓動shell腳本時,輸出又是正確。檢查定時任務,也可以確定是正確。
於是再次運行定時任務,結束後, crontab 日誌 /var/spool/mail/zhang 竟然有提示,發現新大陸,立刻去看了下日誌,發現裏面有這麼一句錯誤
提示:cat: ../local_time: No such file or directory
local_time 是一個文件,在shell腳本的上一級目錄,我沒有使用絕對路徑,而是相對路徑。在定時任務裏,必須使用絕對路徑,定時任務啓動的腳本里,也需要絕對路徑。