stderr stdout to a log file troubles
I originally wrote my script using the korn shell and had to port it to bash on a another server. My script is working find for backing up but noticed that now after the move, I am not getting any output to my log files.
Using Korn shell, this worked for me for some odd reason. This was sending stdout and stderr to a file: Code:
find /home/testuser -depth | cpio -oavc | gzip > /media/backup_drive/test.cpio.gz 2> /media/backup_drive/inc$date.log Here is the line in the script where I expect to see any error go to my errout.log Code:
find /home/testuser -depth | cpio -oavc | gzip > /media/backup_drive/test.cpio.gz 2> /media/backup_drive/errout.log Code:
find /home/testuser -depth | cpio -oavc | gzip > /media/backup_drive/test.cpio.gz 2>&1 >/media/backup_drive/errout.log Code:
find /home/testuser -depth | cpio -oavc | gzip > /media/backup_drive/test.cpio.gz /media/backup_drive/errout.log 2>&1 |
Code:
find /home/testuser -depth | cpio -oavc | gzip > /media/backup_drive/test.cpio.gz 2> /media/backup_drive/inc$date.log 1. standard output of cpio piped to gzip 2. standard error of cpio going to the terminal (it comes from the -v option) 3. standard output of gzip redirected to test.cpio.gz 4. standard error of gzip redirected to inc$date.log If you want the standard error of cpio redirected to a file you should move the 2> redirection immediately after the cpio command: Code:
find /home/testuser -depth | cpio -oavc 2> /media/backup_drive/inc$date.log | gzip > /media/backup_drive/test.cpio.gz |
your awesome,
Thank you for your guidance. I was able to enclose the whole statment like: Code:
(find /home/testuser -depth | cpio -oavc | gzip >/media/backup_drive/test.cpio.gz) 2>/media/backup_drive/errout.log Regards |
I've not tested in ksh (I will deepen into this as soon as I have a Korn shell at hand). Anyway, using a subshell to enclose the pipe chain is a nice idea. Well done! :)
|
All times are GMT -5. The time now is 06:55 AM. |