Explains how to verify and capture output of cron, anacron, and at scheduled jobs on CentOS Stream 8 using system logs, journalctl, and systemd-cat.
Hello, and welcome to this lesson on verifying the completion of scheduled jobs on CentOS Stream 8 (and similar Linux systems). By default, cron, anacron, and at write activity to the system logging facility. That makes it straightforward to confirm whether scheduled jobs ran and, when needed, to capture their output.
System administrators frequently need to verify that scheduled tasks completed successfully or produced the expected output. Knowing where and how cron/anacron/at log their activity helps you troubleshoot failures, capture output, and set up notifications.
Cron records job execution events in /var/log/cron. The log lines include the literal “CMD” for executed commands, making it easy to filter for executions:
Note: Some systems include the command output in the logs under keys like “CMDOUT” or similar. If you expect output from a cron job, search /var/log/cron for CMDOUT or query the journal with journalctl.When finished testing, remove the user crontab entry:
The system-wide crontab at /etc/crontab sets environment variables and shows the expected syntax (including the user field). It also contains MAILTO, which cron/anacron uses to email job output if system mail is configured:
Copy
[aaron@LFCS-CentOS ~]$ cat /etc/crontabSHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=root# Example of job definition:# .---------------- minute (0 - 59)# | .------------- hour (0 - 23)# | | .---------- day of month (1 - 31)# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat# | | | | |# * * * * * user-name command to be executed
Anacron is designed for systems that may be powered off periodically. Jobs use a named identifier, which simplifies searching logs. Example /etc/anacrontab:
Copy
# /etc/anacrontab: configuration file for anacronSHELL=/bin/shPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=rootRANDOM_DELAY=45START_HOURS_RANGE=3-22# period in days delay in minutes job-identifier command1 5 cron.daily nice run-parts /etc/cron.daily7 25 cron.weekly nice run-parts /etc/cron.weekly@monthly 45 cron.monthly nice run-parts /etc/cron.monthly1 10 test_job /bin/echo "Testing anacron"
To run anacron jobs immediately (suppress random delay), use:
Copy
[aaron@LFCS-CentOS ~]$ sudo anacron -n
Force execution regardless of last-run timestamps with -f:
Copy
[aaron@LFCS-CentOS ~]$ sudo anacron -n -f
Anacron logs show start/stop events in /var/log/cron, but they typically only note that output was produced rather than including the full stdout. Example:
Copy
[aaron@LFCS-CentOS ~]$ sudo grep anacron /var/log/cronMar 24 01:01:01 LFCS-CentOS anacron[8903]: Anacron started on 2022-03-24Mar 24 01:01:01 LFCS-CentOS anacron[8903]: Will run job `test_job' in 12 min.Mar 24 01:13:01 LFCS-CentOS anacron[8903]: Job `test_job' startedMar 24 01:13:01 LFCS-CentOS anacron[8903]: Job `test_job' terminated (produced output)Mar 24 01:13:01 LFCS-CentOS anacron[8903]: Normal exit (1 job run)
Capture anacron job output in the systemd journal by piping to systemd-cat. Edit the job entry:
at schedules one-time jobs. To schedule a job to run in one minute and capture its output to the journal:
Create the at job; after entering your commands finish with Ctrl-D:
Copy
[aaron@LFCS-CentOS ~]$ at 'now + 1 minute'warning: commands will be executed using /bin/shat> echo "My at job produced this output" | systemd-cat --identifier=at_scheduled_backupat> <Ctrl-D>job 4 at Thu Mar 24 01:22:00 2022
The at daemon logs job starts to /var/log/cron:
Copy
[aaron@LFCS-CentOS ~]$ sudo grep atd /var/log/cronMar 24 01:04:00 LFCS-CentOS atd[9079]: Starting job 2 (a0000201a3224c) for user 'aaron' (1000)Mar 24 01:07:00 LFCS-CentOS atd[9319]: Starting job 3 (a0000301a3224f) for user 'aaron' (1000)
Because we piped the job to systemd-cat, its output appears in the journal:
Copy
[aaron@LFCS-CentOS ~]$ journalctl | grep at_scheduled_backupMar 24 01:07:00 LFCS-CentOS at_scheduled_backup[9326]: My at job produced this outputMar 24 01:23:14 LFCS-CentOS at_scheduled_backup[10028]: My at job produced this output
Use journalctl to search by custom identifiers when you pipe output through systemd-cat.
If your distribution doesn’t use /var/log/cron, check /var/log/messages or /var/log/syslog, or query the journal directly.
Configure MAILTO in /etc/crontab or per-user crontab if you have local mail delivery enabled and prefer email notifications for output.
On some distributions, scheduled-job messages are recorded in /var/log/messages or /var/log/syslog instead of /var/log/cron. If you don’t find entries in /var/log/cron, search those files or use journalctl to query the systemd journal.