【crontab】“bad minute”及“errors in crontab file, can't install”錯誤處理

secooler發表於2010-04-15
今天有朋友提到,在使用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 --

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-659881/,如需轉載,請註明出處,否則將追究法律責任。

相關文章