Cheatsheet: Linux Crontab


- PDF Link: cheatsheet-cron-A4.pdf, Category: linux
- Blog URL: https://cheatsheet.dennyzhang.com/cheatsheet-cron-A4
- Related posts: CheatSheet: shell, #denny-cheatsheets
1.1 Cron job – create
Name | Comment |
---|---|
Create cron job runs every 5 mins | */5 * * * * /root/mycommand.sh |
Runs every Friday at 9:10 AM | 10 9 * * 5 /root/mycommand.sh |
Runs every midnight | 0 0 * * * /root/mycommand.sh |
Redirect output to log file | 0 0 * * * /root/mycommand.sh >>/var/log/mycron.log 2>&1 |
Install crontab by script | Put file to /etc/cron.d. Remember to set env |
1.2 Cron job – common
Name | Comment |
---|---|
Find crontab daemon process | pgrep crond |
List cron jobs created by automation | ls -lth /etc/cron* |
List cron jobs created by me | crontab -l |
Changing default crontab editor | export EDITOR=vim , export VISUAL=”nano” |
1.3 At
Name | Comment |
---|---|
List all currently-queued at jobs | atq |
Remove a job | atrm $jobid |
1.4 Shutdown
Name | Comment |
---|---|
Shutdown system now | shutdown -r now |
Shutdown system in 5 mins | shutdown -r +5 |