LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   stderr stdout to a log file troubles (https://www.linuxquestions.org/questions/linux-software-2/stderr-stdout-to-a-log-file-troubles-913167/)

metallica1973 11-12-2011 08:56 AM

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
in my errout.log its all garbage. I tried everything, stdout and stderr to a log file but the same gargage:

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
Any ideas ???

colucix 11-12-2011 09:21 AM

Code:

find /home/testuser -depth  | cpio -oavc | gzip > /media/backup_drive/test.cpio.gz 2> /media/backup_drive/inc$date.log
Here you have:
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

metallica1973 11-12-2011 04:24 PM

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
and it worked. I am assuming that in the korn shell, that is not needed because it was only when I change to using the bash shell is when the issue began.

Regards

colucix 11-12-2011 04:28 PM

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.