Skip to main content
Welcome to our detailed guide on verifying the completion of scheduled jobs on CentOS Stream 8. By default, this operating system logs all events generated by cron, anacron, and at. This guide will show you how to confirm that your scheduled jobs are executing correctly.
CentOS Stream 8 logs provide detailed information including command output, which can be extremely useful for troubleshooting and ensuring that your tasks run as expected.

Verifying Cron Jobs

Begin by reviewing your user-specific crontab. To open your crontab for editing, run:
In this example, two commands have been added to the crontab, scheduled to run every minute:
These commands output their respective messages every minute. After adding these jobs, wait at least one minute before checking the logs. To view cron log entries, execute:
You should see log entries resembling the following:
These log entries display the execution time, command details, and output. If you wish to view only executed command logs, filter the logs using:
When you are finished testing or need to remove the current crontab settings, clear them with:

Reviewing the System-Wide Crontab

The system-wide crontab is a useful reference for understanding cron syntax and configuration. To view its content, run:
You will see content similar to this:
Notice the MAILTO setting, which directs the output of cron jobs to the specified user (in this example, root). This ensures that the results of cron jobs are mailed, providing an additional layer of monitoring.

Verifying Anacron Jobs

Anacron is designed to schedule jobs on daily, weekly, or monthly intervals and ensures that they are executed even if the system was off at the scheduled time. Inspect the anacrontab configuration with:
You should see content similar to:
The MAILTO directive ensures that the output for each job, such as test_job, is sent to the specified email recipient. Since waiting a full day for testing isn’t practical, you can manually trigger anacron jobs with:
To focus on anacron-specific log messages, filter the cron log with:
For example, you’ll see log entries like:
If you need logs exclusively for test_job, further filter by:

Enhancing Test Job Logging for Anacron

To capture command output from an anacron job more clearly, modify the job command to pipe its output to systemd-cat with a custom identifier. Edit /etc/anacrontab:
Update the test_job line as follows:
After saving your changes, force anacron to run all jobs irrespective of their previous status using:
Then, view the system log to find the output:
You should see entries similar to:
Once you finish testing, remember to remove or comment out the modified logging command if it is no longer required.

Verifying at Jobs

The at command schedules one-time jobs. To schedule a job to run in one minute, enter:
After this command, you will be prompted to enter the command you wish to run. For example:
Press Control-D (Ctrl+D) to signal the end of input. The system will display a message like:
To view the at job log entries:
You should see log lines indicating the start of the job, for example:
Keep in mind that the default logging for at jobs does not capture the command output. To log the output, schedule an at job by piping its output to systemd-cat:
Then, when prompted, enter:
Once the job executes, review the log output with:
Depending on your system settings, you might also find relevant messages in /var/log/messages or /var/log/syslog.

Conclusion

This guide has detailed how to verify the successful execution of scheduled jobs using cron, anacron, and at on CentOS Stream 8. By examining log files and, when necessary, modifying your job commands to capture their output, you can ensure that your scheduled processes are running correctly and troubleshoot issues as they arise. For further queries and comprehensive documentation on cron, anacron, or at scheduling, you might want to visit the CentOS Documentation. Thank you for reading, and please proceed to the next section for additional demonstrations and related topics.

Watch Video

Practice Lab