LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-12-2011, 08:56 AM   #1
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,113

Rep: Reputation: 57
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 ???
 
Old 11-12-2011, 09:21 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,452

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
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
 
Old 11-12-2011, 04:24 PM   #3
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,113

Original Poster
Rep: Reputation: 57
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
 
Old 11-12-2011, 04:28 PM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,452

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to tell if a file is outputing to STDOUT or STDERR? xskycamefalling Linux - Newbie 5 05-15-2009 12:52 AM
Cannot redirect all stdout and stderr into file hawkgao Programming 2 05-12-2009 09:14 AM
send stderr to a file and also to stdout pranavchoudhary Linux - Newbie 7 08-25-2008 01:57 AM
Shell script - stdout & stderr to terminal and file jantman Linux - Software 1 12-07-2006 04:34 PM
redirecting stdout and stderr to a file Avatar33 Programming 4 03-12-2005 07:55 AM


All times are GMT -5. The time now is 06:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration