Cron Jobs – Where Does the Output of /etc/cron.hourly Scripts Go?

cronloggingmailbox

  1. Say I have a script named "testcron" containing the following:

    #!/bin/bash
    echo This script ran on $(date)

  2. I then set the permissions: chmod ug+x testcron

  3. Finally, I copy this script to /etc/cron.hourly

  4. And I wait for something to happen at the next hour.

So, I found in the /var/log/cron the following entry:

Jul 17 12:01:02 localhost run-parts(/etc/cron.hourly)[13218]: starting testcron
Jul 17 12:01:02 localhost run-parts(/etc/cron.hourly)[13240]: finished testcron

However, I could not find the script's actual output anywhere. Where does the output of this script go? Is it mailed? The root has no mail account. Can I redirect the mail to another user for just this script or will all mail output end up in the user's account? Does it go to /var/log/messages? What is the correct way redirect the output to, say, a dedicated log file?

Note: The script I included above doesn't actually do anything useful but I want to adapt the principles to another script that does.

OS: centos 7

Thanks to all in advance,
Allan

Best Answer

On CentOS, it doesn’t seem to be logging output anywhere, just the fact that the cron has executed is stored in /var/log/cron.

If you need the output, you can use standard shell redirection. First create a file:

touch /var/log/cronoutput

Then capture the output of your cron, example:

* * * * * echo "hey" >> /var/log/cronoutput

Output:

tail /var/log/cronoutput
hey
hey
hey
hey