[CentOS] Runing a script under cron. Append stdout and, stderr to a log file, propagate stderr back to cron for email, reporting

David G. Miller dave at davenjudy.org
Sun Sep 23 14:13:34 UTC 2007


"Alexander Georgiev" <alexander.georgiev at gmail.com> wrote:

> I want to run a rsync-ing script in cron, generating a very verbose
> -vv rsync log in a log file. The log file should combine both stderr
> and stdin, which is easy:
>
>      backup.sh >>/var/log/backup.log 2>&1
>
> However, I would like to propagate only stderr to cron - in case there
> has been an error, cron will mail me the assembled stderr output.
If you just want STDERR to get mailed to root (or wherever you specify), 
remove the "2>$1" from your cron entry.  This is what instructs the 
shell to combine STDOUT with STDERR.  Your cron entry should look like:

backup.sh >>/var/log/backup.log >> /var/log/backup.log


to append STDOUT output to backup.log.  cron automatically mails any 
output from programs.

Cheers,
Dave

-- 
Politics, n. Strife of interests masquerading as a contest of principles.
-- Ambrose Bierce




More information about the CentOS mailing list