RHCSA Practical Lab Series β Configuring Cron Jobs
π Lab 5: Automating Tasks with Cron Jobs
π Objective
In this lab, you will:
β Enable and verify the cron daemon (crond)
β Schedule a cron job for user jack
to run a command daily at 14:23
β Verify the scheduled task execution
π Step 1: Ensure Cron Service is Running
πΉ Check if crond
is active:
[root@node1 ~]# systemctl status crond
πΉ If the service is not running, start and enable it:
[root@node1 ~]# systemctl enable --now crond
π Tip: The --now
flag ensures that crond
starts immediately and remains enabled after reboots.
π Step 2: Schedule a Cron Job for User jack
πΉ Edit the cron jobs for user jack
:
[root@node1 ~]# crontab -e -u jack
πΉ Inside the crontab editor, add the following line:
23 14 * * * /usr/bin/echo "Automated task executed" > /home/jack/cron_output.log 2>&1
π Explanation:
23 14 * * *
β Runs the command every day at 14:23 (2:23 PM)/usr/bin/echo "Automated task executed"
β Prints a test message> /home/jack/cron_output.log 2>&1
β Saves output and errors to a log file
β If added successfully, the job is now scheduled!
π Step 3: Verify the Scheduled Cron Job
πΉ List all cron jobs for jack
:
[root@node1 ~]# crontab -l -u jack
πΉ Expected Output:
23 14 * * * /usr/bin/echo "Automated task executed" > /home/jack/cron_output.log 2>&1
β If the entry appears, the job has been correctly scheduled.
π Step 4: Validate Execution
πΉ After the scheduled time (14:23), check the log file:
[root@node1 ~]# cat /home/jack/cron_output.log
πΉ Expected Output:
Automated task executed
β If this output appears, the cron job is working!
π Troubleshooting:
- Ensure user jack is allowed to use cron (
/etc/cron.allow
or/etc/cron.deny
should not block the user).
If the job does not run, check the cron logs:
[root@node1 ~]# journalctl -u crond --since "15 minutes ago"
β Final Summary
β Enabled and verified the cron service
β Created a cron job for jack
to execute at 14:23 daily
β Confirmed that the cron job executes correctly and logs output
π Next Lab: Configuring a Shared Directory with Group Ownership
π© Subscribe for more RHCSA exam labs and hands-on tutorials! π