5 */2 * * * /usr/bin/pacman -Syuw --noconfirm && pkill -RTMIN+8 i3blocks
*/30 * * * * /usr/bin/updatedb
For details see man 4 crontabs
So for our Monday at 3:30 AM job we would do the following:
.---------------- minute (0 - 59)
| .------------- hour (0 - 23)
| | .---------- day of month (1 - 31)
| | | .------- month (1 - 12) OR jan,feb,mar,apr ...
| | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
| | | | |
* * * * * # user-name command to be executed
30 3 * * 1 apt -y update && apt -y upgrade
I’ll cover a few basics before playing around with cron. First, cron also uses a daemon (crond) that reads different configuration files. There’s a cron file for each user in the /etc/cron.d/ directory, and the /etc/crontab file is system-wide. Every user manages their own scheduled jobs and cron configuration file.
cron (more here) has been automating all the things for the last 40+ years. Cron jobs are scheduled scripts that can run at fixed times or fixed intervals.
Each user on a Unix system has a set of scheduled tasks, visible using the crontab command. The file is in a very simply format that gives the date and time of the script that runs.
The at command is a friendlier alternative, here’s an example of firing a command at 1145 on Jan 31 (from here).
echo "cc -o foo foo.c" | at 1145 jan 31