RHCSA Practical Lab Series – Configuring Cron Jobs

Expertise in Cloud, Networking & DevOps
Photo by Clay Banks / Unsplash

πŸ” 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! πŸš€

Read more