cheat:crontab
---
tags: [ job, scheduler, periodic ]
---
# set a shell
SHELL=/bin/bash
# set a PATH
PATH=/usr/bin:/usr/sbin:/usr/local/bin
# incorrect way of seeting PATH
PATH=$PATH:/do/not/do/this
# crontab format
* * * * * command_to_execute
- - - - -
| | | | |
| | | | +- day of week (0 - 7) (where sunday is 0 and 7)
| | | +--- month (1 - 12)
| | +----- day (1 - 31)
| +------- hour (0 - 23)
+--------- minute (0 - 59)
# example entries
# every 15 min
*/15 * * * * /home/user/command.sh
# every midnight
0 0 * * * /home/user/command.sh
# every Saturday at 8:05 AM
5 8 * * 6 /home/user/command.sh
# compute your crontab periodicity format online
https://crontab.guru/
# be careful with % sign (percent), it has special meaning, see https://crontab.guru/ for explanation
% signs must be escaped such as \%
# view log
journalctl | grep CRON
tldr:crontab
# crontab
# Schedule cron jobs to run on a time interval for the current user.
# More information: <https://crontab.guru/>.
# Edit the crontab file for the current user:
crontab -e
# Edit the crontab file for a specific user:
sudo crontab -e -u user
# Replace the current crontab with the contents of the given file:
crontab path/to/file
# View a list of existing cron jobs for current user:
crontab -l
# Remove all cron jobs for the current user:
crontab -r
# Sample job which runs at 10:00 every day (* means any value):
0 10 * * * command_to_execute
# Sample crontab entry, which runs a command every 10 minutes:
*/10 * * * * command_to_execute
# Sample crontab entry, which runs a certain script at 02:30 every Friday:
30 2 * * Fri /absolute/path/to/script.sh
$
cheat.sh