- Little Background
- Write your cron job
In simple words, it is a scheduler
runs a specified task at a specified time
to automate any repeated task like syncing data or taking backups etc.
for writing a cron file you just need
(specify the time)+ (specify the task)
In General to specify the time we have 5 parameters (* * * * *)
- day (month)
- day (Week)
45 23 * * 6 /home/oracle/scripts/export_dump.sh
In addition to this we could use some arbitrary scheduler expression such as
This will run the script once in a week.
Cron expression syntax is very important for it to work use websites like https://crontab.guru/ and ensure that it works properly.
Although cron is installed in most Linux distributions you can check if it is present or not.
crontab and check.
and since cron uses vi by default you may use the below command to edit it using your favorite editor
EDITOR=/usr/bin/vim crontab -e
Open up your crontab and write
0 0 * * * date >> /tmp/cron_output
This will run every day at 00:00 in 24-hour format or 12:00 am in 12-hour format and will output the current date to /tmp/cron_output.
- Tests your cron job before deploying.
- Remember that cron jobs run on a separate thread(daemon thread) and sometimes may have different behavior than intended.
Stay tuned for more.
Next coming up: Sending Automated WhatsApp message using cron