今天有朋友提到,在使用crontab定制後台定時備份任務時報出「badHour」及「errors in crontab file, can't install」錯誤。
經確認,根本原因是crontab文件中時間格式定義不正確導致的。
簡單記錄一下這個問題,同時確認一下crontab中時間格式的規範,供參考。
1.具體報錯信息如下
ora10g@secDB /home/oracle$ crontab -e
no crontab for oracle - using an empty one
crontab: installing new crontab
"/tmp/crontab.XXXXcz4Lql":1: bad hour
errors in crontab file, can't install.
Do you want to retry the same edit?
Enter Y or N
Do you want to retry the same edit?
Enter Y or N
Do you want to retry the same edit?
Enter Y or N
Do you want to retry the same edit?
Enter Y or N
Do you want to retry the same edit?
Enter Y or N
Do you want to retry the same edit?
Enter Y or N
Do you want to retry the same edit? N
crontab: edits left in /tmp/crontab.XXXXcz4Lql
2.crontab時間格式內容
* * * * * command
M H D m d command
分 時 日 月 周 命令
第1列表示分鐘1~59 每分鐘用*或者 */1表示
第2列表示小時1~23(0表示0點)
第3列表示日期1~31
第4列表示月份1~12
第5列標識號星期0~6(0表示星期天)
第6列要運行的命令或腳本內容