Alexander Georgiev
2007-Sep-22 14:11 UTC
[CentOS] Runing a script under cron. Append stdout and stderr to a log file, propagate stderr back to cron for email reporting
Dear List,
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.
I tried the following:
$ (./backup.sh > /var/log/backup.log) 2>&1 | tee -a
/var/log/backup.log
which propagates the stderr to cron, but lines written to
/var/log/backup.log are out of sequence - for example if the contents
of backup.sh are:
#!/bin/bash
echo "out 1" >&1
echo "out 2" >&1
echo "out 3" >&1
echo "out 4" >&1
echo "err 5" >&2
echo "out 6" >&1
echo "out 7" >&1
echo "out 8" >&1
I get in /var/log/backup.log:
out 1
out 2
out 3
out 4
out 6
out 7
out 8
err 5
I would like the lines in their initial sequence.
Do you know a shell trick or a tool that I can use to achive desired goal?
Best regards,
alex
Ignacio Vazquez-Abrams
2007-Sep-22 15:04 UTC
[CentOS] Runing a script under cron. Append stdout and stderr to a log file, propagate stderr back to cron for email reporting
On Sat, 2007-09-22 at 17:11 +0300, Alexander Georgiev wrote:> I would like the lines in their initial sequence. > > Do you know a shell trick or a tool that I can use to achive desired goal?Can't be done. stdout and stderr aren't synchronized. -- Ignacio Vazquez-Abrams <ivazqueznet at gmail.com> PLEASE don't CC me; I'm already subscribed -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part URL: <http://lists.centos.org/pipermail/centos/attachments/20070922/c9b70ec4/attachment-0001.sig>
Possibly Parallel Threads
- Runing a script under cron. Append stdout and, stderr to a log file, propagate stderr back to cron for email, reporting
- Appending diagnostic information to all lines sent to stdout and stderr
- Updates? Last samba package from RedHat? Cd images for update 3?
- SNAT on IPSEC tunnel with kernel 2.6/KAME tools?
- should I rush to update to Centos 3.3