Using `cron` jobs allow us to run processes according to a recurring schedule. We can set them to run at set times at regular intervals, to perform functions like backups, send emails, or most anything else we might want to do, which can be very useful for a System Administrator.
Successfully complete this lab by achieving the following learning objectives:
- Verify That the crond Service Is Enabled and Running
crond.serviceis active and enabled:
systemctl status crond.service
If we see an active (running) status, then everything is good to go.
- Verify that /usr/local/bin/loadavg.sh is Executable for All and Produces Correct Output
Check permissions on
ls -l /usr/local/bin/loadavg.sh
Make it executable:
chmod a+x /usr/local/bin/loadavg.sh
Run the script:
Check to see if the script sent data to
We should see a timestamp and the three load averages in there.
- Create a cron Job that Executes /usr/local/bin/loadavg.sh Once per Minute During the Hours of 8AM-5PM on Monday through Friday
crontab -eto create the following content:
# Min Hour DoM Month DoW Command * 8-17 * * 1-5 /usr/local/bin/loadavg.sh
Save the cronjob and check our work:
- Verify Cronjob is Running and Producing Correct Output
Again, we could verify
crond.serviceis running using
systemctl. If we want to know whether our job is running or not, we can run
tail /var/log/cronafter a few minutes, and we should see entries in there for our
loadavg.shscript. We should also take a look at the log that the script is writing to, with:
systemctl status crond.service tail /var/log/cron cat /var/log/loadavg.log
If the job is running, then we’ll see contents like we did when we ran the script manually, once a minute.