Help Link: Ubuntu Help
What is Cron?
Cron is a daemon used for scheduling tasks to be executed at a certain time. Each user has a crontab file, allowing them to specify actions and times that they should be executed. There is also a system crontab, allowing tasks such as log rotation and locate database updating to be done regularly.
What Is Crontab?
A crontab is a simple text file that holds a list of commands that are to be run at specified times. These commands, and their related run times, are controlled by the cron daemon and are executed in the system’s background. More information can be found by viewing the crontab’s man page.
Assume that you have command and you want to run that command at an specified time
for example I have made a sh file with this line
saving the file naming tareqFirstCron.sh
from terminal you can test it by running to run it just go to the folder where you saved. Then type:
it will create a directory at /home
now delete the directory. we want to create the director at 2 am everynight
Steps to use cron :
1. open terminal
2.type crontab -e. This will open an editor where we can write crontab commands
3.the format of the line is this :
minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday), command
for our example we will add this line
00 02 * * * sh /path_to_saved_sh_file/tareqFirstCron.sh
4. Now Press ctrl+O
5. press enter
Now go to sleep by running on the machine .. and wake up at 2 am at night
you will see a directory is created at /home ..
that means the command is executing at fixed time
for more example ask google ..