Cron
We can setup commands to be called repeatedly using crontab
command.
A command can be added using crontab -e
command which opens an editor where we can add our command like below,
* * * * * echo hello world
where these stars are mean
# * * * * * <command to execute>
# | | | | |
# | | | | day of the week (0–6) (Sunday to Saturday)
# | | | month (1–12)
# | | day of the month (1–31)
# | hour (0–23)
# minute (0–59)
For example, scheduling a job every Monday at 4AM would look like this,
0 4 * * * echo Some work
We can specify */n
to specify interval of time. For instance, every 5th minute can be specified as */5 * * * *
.
Adding to this, specific time can also be specified using commas ,
such 1,2,3
. For example, */2 2,4,6 * * *
means that to repeat every 2nd minute of second, fourth and sixth hour which is 02:02, 02:04, up until 06:60.