1
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?

More than 5 years have passed since last update.

crontabの設定方法メモ

Posted at

概要

cronの使い方をよく忘れるのでメモとして残しておく。


cronとは?

クーロンではなくクロンが正しい呼び方のようです。
クロンとは自動実行をするためのデーモンのことです。
LinuxやmacなどのUnix系の環境で定期実行したいコマンドがある場合はcronに登録しておくことで指定した時刻にコマンドが実行されます。


設定方法

  • まずはcrontabを開きます
# crontab -e

これで編集モードでcrontabが開かれます。設定によりますが通常エディタはvimとなります。

  • そして以下のように書きます。
分 時 日 月 曜日 実行したいコマンド

曜日は0(または7)を日曜日として番号で指定します。
「*」を入れるとワイルドカード扱いになり、全ての分や時間、曜日で設定したコマンドが事項されます。
以下の例の場合、毎月の火曜日の毎時15分に/tmp/testというファイルにHelloと上書きすることになります。

15 * * * 2 echo "Hello" >> /tmp/test
1
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
1
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?