Linux 101: The best way to use cron

Persevering with together with his Linux 101 collection, Jack Wallen introduces you to the fundamentals of activity scheduling with cron.

Picture: Pixabay

For the admins who’re new to Linux, I need to introduce you to the cron software. What’s cron? Merely acknowledged, cron permits you to create scheduled jobs on a Linux system. Say, as an example, you’ve got a backup script, known as You have positioned that script in /usr/native/bin, so it may be executed globally and also you need to make sure that the backup occurs at both a particular time of day or usually on a sure day of the week. 

How do you do that? You invoke cron. 

To make use of this, you add conjobs to your consumer’s crontab file. Go browsing to your Linux server and problem the command:  

crontab -l

This may record out all present cron jobs. To create a brand new cron job, you edit the crontab file. To do that, problem the command: 

crontab -e

You’ll then add a line on the backside of that file to schedule the working of your backup script. Here is the place it will get a bit difficult. The primary part of the road is the place you declare when the job is to run. In the beginning of that line there are 5 slots for time, that are (from left to proper): Minutes (0-59), hours (0-23), day of month (1-31), month (1-12), day of week (0-6, though you should utilize Sunday, Monday, Tuesday, and so forth., and Sunday may be represented by 0, 7, or Sunday). 

For instance you need that backup job to run each Sunday at 11pm. That entry may very well be 0 23 * * 0. A star signifies the job is to occur each iteration. On this case we have indicated the job ought to occur Sunday at 11pm, each week and each month. The remainder of this line would come with the specific path to the executable, so /usr/native/bin/ 

Our total line could be 0 23 * * 0 /usr/native/bin/ Save the crontab file with the Ctrl+X mixture (if nano is your editor of selection), and the job is scheduled. You would possibly need to make sure that your job is listed with the crontab -l command. 

Congratulations, you have simply scheduled your first cron job. This ought to be simply sufficient to get you going with this highly effective Linux scheduling software.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the newest tech recommendation for enterprise professionals from Jack Wallen.

Additionally see

Source link