0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cronの使い方

Last updated at Posted at 2025-03-25
目次
  • cronとは
  • crontabの使い方
  • 設定方法について
  • 設定値について
cronとは

cronとは、定期的に処理を実行するプログラムのことです。
crontabでcronを設定することで、処理を定期的に実行することができます。

crontabの使い方
  • 現在の設定を表示する
crontab -l
  • 設定内容を編集する
crontab -e
  • 設定内容を削除する
crontab -r

編集画面から設定内容の先頭に「#」をつけることで繰り返し処理を止めることもできます。

設定方法について

以下のコマンドを実行すると、viエディタと同じ操作で修正できる画面に移動します。

crontb -e

左から「分」「時」「日」「月」「曜日」の順に記載します。
以下のように設定した場合、毎分コマンドが実行されます。

* * * * * [実行コマンド]
設定値について
  • 数値の範囲
    「*」を以下の範囲内の値に設定することで、毎分以外の繰り返し処理にすることができます。
設定項目 数値
0~59
0~23
1~31
1~12
曜日 0~7
  0,7:日曜、1:月曜、2:火曜、3:水曜、4:木曜、5:金曜、6:土曜
  • より柔軟な設定
指定方法 設定例 設定内容
複数指定 15,45 * * * * [実行コマンド] 15分、45分に実行
間隔指定 */10 * * * * [実行コマンド] 10分おきに実行
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?