LoginSignup
0
0

More than 3 years have passed since last update.

crontabの記述法

Posted at

Qiita初投稿です!!自分用に備忘録としてcrontabの設定方法を置いておきます。

crontabのオプション

crontab [ -u ユーザー名 ] { -l| -e | -r }

-u オプション

cronを設定するユーザーを指定する。省略可能。省略するとcrontabを実行したユーザーになる。

-l オプション

現在のcrontabの記述を表示する。

-e オプション

crontabの設定を編集する。

-r オプション

crontabの削除。注意が必要!!!!

crontabの書式

分 時 日 月 曜日 shellscriptとかのファイルパス(またはコマンド)
- 各項目半角空ける
- 曜日は月曜から1で日曜が7

ex.毎日9時から22時までの30分ごとにジョブを実施
*/30 9-21 * * * comand ・・・9-22までにすると21:30にも実施されちゃう、、、
ex.毎週土曜日の21時に実施
0 21 * * 6 comand
ex.4月1日の15時に実施
0 15 1 4 * comand

標準出力&エラー出力

cronには標準出力とエラー出力をメールで送信する機能がデフォルトでついているので、
頻繁にやるジョブを知らずに放っておくと /var/spool/mail/配下がすぐにいっぱいになってしまう、、、
そこでメールを停止させる。

分 時 日 月 曜日 comand > dev/null 2>&1 ・・・標準出力やエラー出力ともに停止

分 時 日 月 曜日 comand 1 > dell/null ・・・エラー出力だけ送信

分 時 日 月 曜日 comand > ファイルパス > 2>&1 ・・・ログ出力先のファイルパスを指定する

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