Cron式 チートシート
cron構文のクイックリファレンス。フィールド構文、特殊文字列、フィールド値、時間指定例、システムタスク、バックアップタスク、環境変数、トラブルシュートを網羅
60 件のコマンド
* * * * * command毎分実行(分 時 日 月 曜日)
* * * * * /path/to/script.shcrontab -e現在のユーザーのcrontabを編集
crontab -ecrontab -l現在のユーザーのcrontabを表示
crontab -lcrontab -r現在のユーザーのcrontabを削除
crontab -rcrontab -u {user} -e指定ユーザーのcrontabを編集
sudo crontab -u www-data -ecrontab -u {user} -l指定ユーザーのcrontabを表示
sudo crontab -u www-data -l/etc/crontabシステムcrontabファイル(ユーザー指定あり)
sudo vi /etc/crontab/etc/cron.d/追加のcronジョブ定義ディレクトリ
ls /etc/cron.d/@rebootシステム起動時に1回実行
@reboot /path/to/startup.sh@yearly / @annually年1回実行(1/1 0:00)
@yearly /path/to/yearly-report.sh@monthly月1回実行(毎月1日 0:00)
@monthly /path/to/monthly-cleanup.sh@weekly週1回実行(日曜 0:00)
@weekly /path/to/weekly-backup.sh@daily / @midnight日1回実行(毎日 0:00)
@daily /path/to/daily-task.sh@hourly毎時実行(毎時 0分)
@hourly /path/to/hourly-check.sh* (asterisk)全ての値にマッチ
* * * * * → every minute, (comma)複数の値を列挙
1,15,30 * * * * → at :01, :15, :30- (hyphen)値の範囲を指定
1-5 * * * * → minutes 1 through 5/ (slash)ステップ値(間隔指定)
*/5 * * * * → every 5 minutes分: 0-59分フィールドの範囲
30 * * * * → at :30 every hour時: 0-23時フィールドの範囲
0 9 * * * → at 9:00 AM日: 1-31日フィールドの範囲
0 0 1 * * → 1st of every month月: 1-12 / JAN-DEC月フィールドの範囲
0 0 1 1 * → January 1st曜日: 0-7 / SUN-SAT曜日フィールドの範囲(0と7=日曜)
0 0 * * 1 → every Monday*/5 * * * *5分ごとに実行
*/5 * * * * /path/to/check.sh*/15 * * * *15分ごとに実行
*/15 * * * * /path/to/monitor.sh0 * * * *毎時0分に実行
0 * * * * /path/to/hourly.sh0 */2 * * *2時間ごとに実行
0 */2 * * * /path/to/bihourlyjob.sh0 9 * * *毎日9:00に実行
0 9 * * * /path/to/morning.sh0 9-17 * * 1-5平日の9時〜17時に毎時実行
0 9-17 * * 1-5 /path/to/business-hours.sh30 2 * * *毎日2:30に実行
30 2 * * * /path/to/nightly.sh0 0 * * 0毎週日曜0:00に実行
0 0 * * 0 /path/to/weekly.sh0 0 1 * *毎月1日の0:00に実行
0 0 1 * * /path/to/monthly.sh0 0 1 1 *毎年1月1日の0:00に実行
0 0 1 1 * /path/to/newyear.sh*/5 * * * * ... >/dev/null 2>&1出力を破棄して実行
*/5 * * * * /path/to/script.sh >/dev/null 2>&10 3 * * * ... >> /var/log/cron.log 2>&1ログファイルに出力を追記
0 3 * * * /path/to/task.sh >> /var/log/cron.log 2>&10 2 * * * apt-get update毎日2:00にパッケージリストを更新
0 2 * * * apt-get update -qq0 4 * * * find /tmp -mtime +7 -delete7日以上前の一時ファイルを削除
0 4 * * * find /tmp -type f -mtime +7 -delete*/10 * * * * /usr/bin/certbot renewSSL証明書の更新をチェック
0 3 * * * /usr/bin/certbot renew --quiet0 6 * * * systemctl restart nginx毎日6:00にNginxを再起動
0 6 * * * systemctl restart nginx*/2 * * * * /path/to/healthcheck.sh2分ごとにヘルスチェックを実行
*/2 * * * * /path/to/healthcheck.sh0 1 * * * mysqldump ...毎日1:00にMySQLバックアップ
0 1 * * * mysqldump -u root dbname > /backup/db_$(date +\%F).sql0 2 * * * pg_dump ...毎日2:00にPostgreSQLバックアップ
0 2 * * * pg_dump -U postgres dbname > /backup/pg_$(date +\%F).sql0 3 * * * tar czf ...毎日3:00にディレクトリをアーカイブ
0 3 * * * tar czf /backup/www_$(date +\%F).tar.gz /var/www0 4 * * * rsync -avz ...毎日4:00にリモート同期バックアップ
0 4 * * * rsync -avz /data/ user@backup:/backup/data/0 0 * * 0 find /backup -mtime +30 -delete毎週日曜に30日以上前のバックアップを削除
0 0 * * 0 find /backup -type f -mtime +30 -delete0 5 * * * aws s3 sync ...毎日5:00にS3へバックアップ同期
0 5 * * * aws s3 sync /backup s3://my-bucket/backup/SHELL=/bin/bashcron実行シェルを指定
SHELL=/bin/bashPATH=...PATHを明示的に設定
PATH=/usr/local/bin:/usr/bin:/binMAILTO=user@example.comcron出力のメール送信先を設定
MAILTO=admin@example.comMAILTO=""cron出力のメール送信を無効化
MAILTO=""HOME=/home/userホームディレクトリを設定
HOME=/home/deployCRON_TZ=timezonecronのタイムゾーンを設定
CRON_TZ=Asia/Tokyogrep CRON /var/log/syslogcronログを確認
grep CRON /var/log/syslog | tail -20journalctl -u cronsystemdでcronログを表示
journalctl -u cron --since todaysystemctl status croncronサービスの状態を確認
systemctl status cronsystemctl restart croncronサービスを再起動
sudo systemctl restart cronrun-parts --test /etc/cron.d/cron.dのスクリプトをテスト実行
run-parts --test /etc/cron.daily/dateサーバーの現在時刻を確認
date && timedatectlwhich {command}コマンドのフルパスを確認
which python3env -i /bin/bash -c 'command'最小環境でコマンドをテスト
env -i /bin/bash -c '/path/to/script.sh'