Persevering with along with his Linux 101 collection, Jack Wallen introduces you to the fundamentals of job scheduling with cron.
For the admins who’re new to Linux, I need to introduce you to the cron software. What’s cron? Merely said, cron means that you can create scheduled jobs on a Linux system. Say, for example, you’ve gotten a backup script, known as backup.sh. You’ve got 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 frequently 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 person’s crontab file. Go browsing to your Linux server and subject the command:
This can listing out all current cron jobs. To create a brand new cron job, you edit the crontab file. To do that, subject the command:
You’d then add a line on the backside of that file to schedule the operating 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. Firstly 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 need to use Sunday, Monday, Tuesday, and so forth., and Sunday might be represented by 0, 7, or Sunday).
To illustrate you need that backup job to run each Sunday at 11pm. That entry could possibly 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/backup.sh.
Our complete line can be 0 23 * * 0 /usr/native/bin/backup.sh. Save the crontab file with the Ctrl+X mixture (if nano is your editor of alternative), 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.