Cron is a Linux utility where you can setup a task in your machine to run automatically, if required in a repetitive manner at a specific time and date.
Such a task that you schedule is called a Cron Job.
Here we'll look into how we can setup a cron job in a Linux machine.
Follow the steps bellow.
Step 1 :
Place the script you want to schedule as a Cron Job to one of the following directories in your machine depending on how often you need to repeat the execution of the script.
- /etc/cron.hourly
- /etc/cron.daily
- /etc/cron.weekly
- /etc/cron.monthly
Step 2 :
Then give correct permissions to the script as follows. Assume script.sh is the script that you need to schedule.
cd /etc/cron.daily chmod 755 script.sh
Step 3 :
Then you should add a new Cron Job to crontab.
crontab -e
Step 4 :
Then you will be prompted with your vi editor in the terminal. Type in the following into the editor and to save it hit ESC key, and then type :w followed by :q to exit.
0 0 * * * /etc/cron.daily/script.sh
This command will make the Cron Job run every night.
Note : Look at the following to identify the different ways of customizing the command given in Step 4.
Blog commenting is an excellent. Thank you for sharing this wonderful piece of information and for sharing helpful insights. Otherwise If any one who want to achieve a goal in linux contact us on 9311002620 or https://htsindia.com/Courses/modular-courses/redhat-linux-administration-training-course
ReplyDeleteCrontab files are simple text files that have a particular format. Each line of a crontab file follows a particular format as a series of fields, separated by spaces and/or tabs. Each field can have a single value or a series of values. A single cron job should take up exactly one line, but this can be a long line (more than 80 characters).
ReplyDeletefor more information click here:how to setup a cron job