crontab
プロセスとシステム
書き方
crontab -e | crontab -l利用者ごとの定期実行表を扱います。cron は PATH がほぼ空でログイン設定も読まないため絶対パスで書く必要があり、`crontab -r` は確認なしで表を丸ごと消します。
よく使うオプション
| オプション | 意味 |
|---|---|
| -e | Edit your table in $EDITOR; it is installed when you save. |
| -l | Print your table. Redirect it somewhere to keep a backup. |
| -r | Delete the whole table at once, with no confirmation. |
| -u <user> | Work on another user's table (root only). |
| m h dom mon dow | The five time fields, then the command. * means every. |
| @reboot / @daily | Shorthand instead of the five fields. |
例
crontab -l > ~/cron.bakBack up the table before touching it.
crontab -eThen add: 0 3 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
crontab -l | grep -v backup.sh | crontab -Remove one line without opening an editor.
何が動いていて何が資源を食っているかを見ます。止める前に何なのかを確かめるのが順番です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. crontab は何をしますか。
利用者ごとの定期実行表を扱います。cron は PATH がほぼ空でログイン設定も読まないため絶対パスで書く必要があり、`crontab -r` は確認なしで表を丸ごと消します。
Q. どう打ちますか。
crontab -e | crontab -l — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは6個です。全部は man crontab にあります。このコマンドはプロセスとシステムの仲間です。
関連するコマンド
man ページ: man crontab