Last active
August 29, 2015 14:25
-
-
Save shoji-mochizuki/86b0e567c26771d04c7c to your computer and use it in GitHub Desktop.
CrontabでEC2を指定の時間にシャットダウンさせる ref: http://qiita.com/shojimotio/items/65f769ef92cc0b7c752b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# crontab -e(編集)と-r(削除)の押し間違い防止 | |
alias crontab='crontab -i ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# コマンドの実行に、デフォルトの /bin/sh ではなく /bin/bash を使用する。 | |
SHELL=/bin/bash | |
# root PATHを設定 | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin:/opt/aws/bin | |
# mailを送信したくない時 | |
MAILTO="" | |
# JSTかUSTかシステムに合わせる。これはJST ログはmessageに書く | |
0 19 * * * shutdown -h now 2>&1 | logger -t shutdown -p local0.info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 23 * * * 23:43に実行 | |
12 05 * * * 05:12に実行 | |
0 17 * * * 17:00に実行 | |
0 17 * * 1 毎週月曜の 17:00に実行 | |
0,10 17 * * 0,2,3 毎週日,火,水曜の 17:00と 17:10に実行 | |
0-10 17 1 * * 毎月 1日の 17:00から17:10まで 1分毎に実行 | |
0 0 1,15 * 1 毎月 1日と 15日と 月曜日の 0:00に実行 | |
42 4 1 * * 毎月 1日の 4:42分に実行 | |
0 21 * * 1-6 月曜日から土曜まで 21:00に実行 | |
0,10,20,30,40,50 * * * * 10分おきに実行 | |
*/10 * * * * 10分おきに実行 | |
* 1 * * * 1:00から 1:59まで 1分おきに実行 | |
0 1 * * * 1:00に実行 | |
0 */1 * * * 毎時 0分に 1時間おきに実行 | |
0 * * * * 毎時 0分に 1時間おきに実行 | |
2 8-20/3 * * * 8:02,11:02,14:02,17:02,20:02に実行 | |
30 5 1,15 * * 1日と 15日の 5:30に実行 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ダメ 2 2 * * * hoge.php > /dev/null 2>&1 | |
良い 2 2 * * * hoge.php > hogee.log 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ダメ PATH=/usr/local/bin:$PATH | |
良い PATH=/usr/local/bin:/usr/bin:/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 2 * * * /bin/sh /etc/hogehoge 2>&1 | Mail [送信先メールアドレス] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 19 * * * shutdown -h now >> shutdown.log 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 19 * * * shutdown -h now 2>&1 | logger -t shutdown -p local0.info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tail -f /var/log/messages | |
Jan 16 11:05:02 ip-172-31-5-106 shutdown: hoge | |
Jan 16 11:06:01 ip-172-31-5-106 shutdown: hoge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo service crond restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment