LoginSignup
46
50

More than 5 years have passed since last update.

cronでシェルスクリプトが動作しない時に確認すべきこと

Last updated at Posted at 2016-07-31

環境はCentOS 6.7
スクリプトは /root/task.sh

確認すべきこと

  • cron は動作しているか
  • 実行権限は付与しているか
  • エラーログは確認したか
  • 実行パスは指定しているか
  • それでもだめなら...

cron は動作しているか

# /etc/rc.d/init.d/crond status
crond (pid  xxxx) を実行中...

crondの起動方法
# /etc/rc.d/init.d/crond start

実行権限は付与されているか

ls -al
-rwx------ 1 root root 10  7月 31 7:06 2016 task.sh

実行権限の付与
chmod +x task.sh

エラーログは確認したか

# cat /var/log/cron
Jul 31 07:06:01 localhost CROND[xxxx]: (root) CMD (/root/task.sh)

コマンドは絶対パスで指定しているか

cat /root/task.sh
/bin/echo helloworld

それでもだめなら...

結果をメールで送信する

crontab -e

MAILTO="hogehoge@gmail.com"
* * * * * /root/task.sh

参考リンク

コンソールで叩くと動くスクリプトがCronで動かない時 – ひげろぐ
cron が実行されない - ナクナイ
crontabがどうしても動かないときに確認すべき3つの点+α - ドキッ!はてなブログに移転しました!

46
50
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
46
50