今天有朋友提到,在使用crontab定制后台定時備份任務時報出“bad minute”及“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 minute
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列要運行的命令或腳本內容
如果能掌握這個crontab的時間格式的定義,基本上就會避免出現“bad minute”錯誤。
3.正確格式樣例一則
ora10g@secDB /home/oracle$ crontab -e
0 22 * * 0-6 /db_backup/dpump_dir/expdp.sh 1>>/db_backup/dpump_dir/expdp.log 2>&1
~
~
這是一個比較常見的使用EXPDP命令定時備份數據庫的例子。
“/db_backup/dpump_dir/expdp.sh”腳本將在每天晚上10點自動運行,同時將運行的日志寫入到“/db_backup/dpump_dir/expdp.log”文件中。
4.如果仍然解決不了問題,可以考慮重新啟動crond服務
注意需要使用root用戶完成服務的重啟。
ora10g@secDB /home/oracle$ su - root
Password:
[root@secDB ~]# /etc/rc.d/init.d/crond restart
Stopping crond: [ OK ]
Starting crond: [ OK ]
5.小結
如果能夠按照規則和操作規范完成維護操作,出錯的概率將會大大的降低,因此平時指定好規范文檔非常的重要。
Good luck.
secooler
10.04.15
-- The End --