Automation Using Linux Crontab to Schedule Task
If you want to run some processes like backup , generate image thumbnail etc.. in the background.
The is an easy way to do this, we can using Crontab to handle this task so it will automatically do the job in your schedule task.
What is Crontab ?
Crontab is found in unix and unix-like O/S, cron derives from chronos greek time and it used to schedule command or execute it periodically.
How to Verify Crontab Running in The System ?
Login into your server and type this command below :
#crontab -l
### you will see someline like example below ###
* * * * * /bin/example-path/example-script.sh
So How To Add a Schedule Task to Crontab ?
Still in your terminal / ssh terminal, type this command below
#crontab -e
You will see a blank screen, you can press INSERT button and start type your crontab command
after that don't forget to save your crontab, press ESC button and type :wq! this will help you save your crontab to the schedule task
Crontab Schedule Explain
Example : * * * * * /bin/testing-path/testing-script.sh
You can see a 5 stars there, the stars will present a different minute, hour, day of month, month and day of week.
- minute (from 0 to 59)
- hour (from 0 to 23)
- day of month (from 1 to 31)
- month (from 1 to 12)
- day of week (from 0 to 6) (0=Sunday)
From the example above the crontab will execute every minute.
Note :
* / star/ asterisk mean EVERY
Another Crontab Example
If you want to run a schedule script at 2AM every Thursday, then you need a following cronjob
0 2 * * 4 /bin/testing-path/testing-script.sh
Example Star Description above:
- minute:
0 - of hour:
1 - of day of month:
*(every day of month) - of month:
*(every month) - and weekday:
1-5(=Monday til Friday)
Recent blog posts |
Recent comments
|
Comments
Post new comment