In this section, we are going to learn how to configure Cron Jobs. We are going to use crontab to set up a Cron Job.
- Open your terminal and go to the
/etc
folder and check the/cron
folders. You will see the following cron folders:/etc/cron.hourly
/etc/cron.daily
/etc/cron.weekly
/etc/cron.monthly
- Now, we will copy our shell script into one the preceding folders.
- If you need to run your shell script to run daily, place it in the
cron.daily
folder. If you need to run it hourly, place it in thecron.hourly
folder, and so on. - Example: Write a script and place it in the
cron.daily
folder. Make the script executable by giving the necessary permissions. - Now, run the
crontab
command:
$ crontab -e
- Press Enter and it will ask for the editor of your type. By default, it will open
vi
editor. In my case, I selectednano
. Now, create acron
command. The syntax for creating thecron
command is:- The number of minutes after the hour (0 to 59...