The software utility Cron is a time-based job scheduler in Unix-like computer operating systems. People who set up and maintain software environments use cron to schedule jobs (commands or shell scripts) to run periodically at fixed times, dates, or intervals. It typically automates system maintenance or administration—though its general-purpose nature makes it useful for things like connecting to the Internet and downloading email at regular intervals.
Normally, CRONIE is installed by default in Linux-Based OS. However, CRONIE is not enable by default in new ARCH LINUX INSTALLATION. This can be checked by digiting in your terminal:
Cronie systemd service must be started and enabled via
systemctl by root
Now, you have to edit your crontab via:
For example to run a command every Monday at 8:00 AM:
In this way you can decide the exact time of the command execution. If you want to run a command at every defined number of minutes ( or hours, day, etc. ) you have to write
*/ before the chosen number (in the example below the command is run every 5 minutes).
SETTING A CRON JOB FOR THE LAST DAY OF THE MONTH
If you want to run a command at 09:00 in the first day of the month, you have to set the third option to 1, as follow
But if you have to run a command or a script at 09:00 in the last day of the month, what can you do? The last day of the month could be 30, 31, 28 or sometimes even 29. So, you can write as follow:
the command will be executed at the 28-th, 29-th, 30-th and 31-th day of the month. How is possible to choose which is the last day between the four days before cited?
Only one thing is always true about the last day of the month: the following day is the first! Thus, once you have verified that tomorrow is the first day of the month, you are sure that today is the last.
The bash command
will give you the current date as a two character number. To get the number of tomorrow:
If that mastches “01”, tomorrow is the first so today is the last day of the month
The square brackets will result in either true or false. If the command between square brackets comes back false, the second command won’t be run. So, only when the command between square brackets come back true, the second command will be run.
The complete crontab will result: