5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Linux]cron設定する時

Posted at

いつもcron設定するときにさまようので、さまよう事のないためのレシピ。

設定内容

# Auto Data Update
0 6 * * * /home/bohe/shell/auto_update.sh > /home/bohe/logs/auto_`date +"\%Y\%m\%d"`.log

時間設定

分 時 日 月 曜日 コマンド
  • 曜日 0~7 [0,7は日曜日]

ログ設定

  • 上書き
> 
  • 追加書き込み
 >>

出力ログに日付をつける

`date +"\%Y\%m\%d"`

設定したら、動作しているかどうかをログで確認しよう

ログ

/var/log/cron

動いていない場合

  • crondは動いていますか?
# /etc/rc.d/init.d/crond status
crond (pid xxx) を実行中...
  • 動いていない場合は起動
# /etc/rc.d/init.d/crond start
  • runlevel 2,3,4,5 で cron を起動させていること
# chkconfig --level 2345 crond on


# chkconfig --list crond
crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off
  • (参考)ランレベル

Linux では、ランレベルと呼ばれる動作モードを指定する事によって、サーバーの動作を変える事が可能になります

 0 システムの停止
 1 シングルユーザーモード
 2 マルチユーザーモード(NFSなし)
 3 マルチユーザーモード(テキストログイン)
 4 未使用
 5 マルチユーザーモード(グラフィカルログイン)
 6 システムの再起動
 

監視を考えて

小規模なお客さんのサーバなどの運用をしている場合には、cronlogでできますね。
これは使えます。

ログファイルは蓄積されてしまうので、logger(1) コマンドを使用して syslog に送って記録するのがおすすめという例がかかれてあります。
これでOKですね。

多重起動を回避するためのスクリプトです。

5
5
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
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?