How can we schedule automatic tasks in Unix

Latest posts by Stratos Matzouranis (see all)
- How can we increase performance on Oracle GoldenGate Replicat target with parallelism? - 19 March 2025
- How to create users in databases that belong to a SQL Server Always On Availability Group - 10 February 2025
- How to create a Logon Trigger to control which users are allowed to connect to an Oracle Database - 13 January 2025
Unix-based operating systems such as Linux and MacOS have the Cron program installed.
Cron allows us to schedule tasks to run automatically over time.
Its usefulness stands out in repetitive tasks.
The editorial
To see the list of all the schedules we already have in cron
crontab –l
To add new schedules or change existing ones
crontab –e
Each entry is a separate program.
The way it is drafted
# ┌───────────── λεπτό (0 - 59)
# │ ┌───────────── ώρα (0 - 23)
# │ │ ┌───────────── μέρα (1 - 31)
# │ │ │ ┌───────────── μήνας (1 - 12)
# │ │ │ │ ┌───────────── ημέρα της εβδομάδας (0 - 6) (0 είναι η Κυριακή)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * * <η εντολή που θα εκτελεστεί>
The order in the asterisks is minutes 0-59, hours 0-23, day 1-31, month 1-12, day of the week 0-6 with 0 being Sunday to begin with. However we can select some days by putting ' , ' between the days.
Examples
To run the test.sh file
Every 5 minutes
*/5 * * * * /home/user/test.sh
Every hour
0 * * * * /home/user/test.sh
At 10 in the morning
0 10 * * * /home/user/test.sh
Every Monday at 10:15 am
15 10 * * 1 /home/user/test.sh
Every first and 15th of the month at 8 am
0 8 1,15 * * /home/user/test.sh
To see the log
tail -f /var/spool/mail/onoma_xristi