Register
It is currently Wed Apr 23, 2014 5:36 pm

need to redirect error messages to a file instead of screen


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Wed Dec 10, 2008 8:58 pm   

Joined: Wed Nov 19, 2008 11:26 am
Posts: 13
Hello

I have a shell script called myShell

I want to redirect error messages (when script is run) to a file called errors.txt instead of printing out on screen

Currently I have the following line at the beginning of the script but it's not having the desired effect...

Code:
myShell 2> error.txt



Please advise

Thank you
Bobby


Top
 Profile  
 PostPosted: Thu Dec 11, 2008 2:10 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
myShell 2&>1 filename

This should redirect all messages outputed to the file. (Actually it redirects the content of 2 to 1)

Problem might be that the program outputting the error isn't doing it right.
The 1 is a "symbol" for stdout (standard output) and 2 is for stderr (standard error output).
The praxis tells us that all errors should be written to stderr, but not all software does this... some just print error messages as a normal stdout and sets a return code to use for error handling (return code is in variable $?).

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Thu Dec 11, 2008 12:12 pm   

Joined: Wed Nov 26, 2008 7:43 pm
Posts: 50
Location: Texas
Try finding what shell you're using it might be helpful. google for "redirect standard error <your shell>"

echo $SHELL

Anyhow, you can try this as well

Redirects everything for Csh.
myShell >& error.txt

Ed


Top
 Profile  
 PostPosted: Sat Dec 13, 2008 4:20 pm   

Joined: Wed Nov 19, 2008 11:26 am
Posts: 13
It's a bash shell. Thank you both for your replies. Much appreciated.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP