STDERR output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting STDERR output
# 1  
Old 11-07-2006
Error STDERR output

Hi,

Need some help here on a script I'm writing. I know that STDERR is normally done is this manner:

script 2>stderr.out

However, if I wanted to output the stderr from a rsh command how do I do that?

Example:

su - username -c "rsh $hostname /opt/gilberteu/scriptname" 1>stdout 2>stderr

If the scriptname doesn't exist, an error will be shown on the screen instead of it going to the stderr file.

Any ideas?
# 2  
Old 11-07-2006
I think I found an alternative:

su - username -c "rsh $hostname /opt/gilberteu/scriptname 2>stderr" 1>stdout
# 3  
Old 11-07-2006
This will clear your douts

1> filename #Redirect stdout to file "filename"
1>>filename #Redirect and append stdout to file "filename"
2> filename #Redirect stderr to file "filename"
2>>filename ##Redirect and append stderr to file "filename"
&> filename ##Redirect both stderr and stdout to file "filename"
# 4  
Old 11-07-2006
The last syntax is not recognized by KSH.
To redirect both stderr and stdout to file "filename", the syntax is :
1>filename 2>&1 or
>filename 2>&1


Jean-Pierre.
# 5  
Old 11-07-2006
Thanks for the response.

I think my alternative works but I am just curious if there's any there is any other way to go about it by NOT creating a stderr file on the remote host.

"rsh $hostname /opt/gilberteu/scriptname 2>stderr" creates the stderr on the remote host instead of the host from where I'm running the rsh from. I wanted the stderr on my local host.

Any ideas?
# 6  
Old 11-08-2006
since STDERR is sent to the screen by the shell and since the error will be on the remote host, redirecting the output of the rsh command to a file should get you what you want ...
Code:
rsh $hostname "/opt/gilberteu/scriptname" > /locdir/locfile

or
Code:
rsh $hostname "cd /remdir; ls -ld remfile" | tee /locdir/locfile

in both cases, you don't need to redirect STDERR to /locdir/locfile because you are not trying to capture the STDERR from the rsh command ... unless you felt like it ...


good luck!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Doubt regarding stderr

Hi All, I am writing a shell script code. and i want the stderr to be send to a file and the stdout to be displayed in terminal. In my shell script code i use a read command to get data from user.read -r -p "Enter the type :" data and while i execute my script i use./my_script.sh 2>... (4 Replies)
Discussion started by: Vinoth R
4 Replies

2. Solaris

can't get stderr port

Hi Experts, i have a solaris 9 OS and i get the following message repeated many time in my /var/adm/messages : Oct 31 16:30:44 baobab rsh: can't get stderr port: Cannot assign requested address have you any idea how can i resolve this issue ??:confused: thanks for help (2 Replies)
Discussion started by: lid-j-one
2 Replies

3. UNIX for Dummies Questions & Answers

how to get stderr

Hello I try to store stderr into a variable, then if this var is not empty i send an email and stop my script. I think my problem is due of "<$dump" into my command line. my bad command line (see samples below on this post) if ! $returnedStr ; then echo ERROR READING DUMP: ... (8 Replies)
Discussion started by: giova
8 Replies

4. Shell Programming and Scripting

Append stderr

Hi everybody. I was used to redirect stderr to a file in this way, calling a generic script:./myScript &> output.logBut now I need something more sophisticated...Inside a bash script I launch an executable in this way:${command} >> "${globalLogFile}"So I redirect the stdout into globalLogFile.... (14 Replies)
Discussion started by: canduc17
14 Replies

5. Shell Programming and Scripting

Output stderr to 2 or more files

Hello all, I tried a few variations but can't get this to work. I am trying output an hourly and daily log. # hourly log file (f1) # daily log file(f2) f1="/app/var/log/hourly/somescript.`date +%Y%m%dT%H0000`.log" f2="/app/var/log/daily/somescript.`date +%Y%m%dT000000`.log" bash... (2 Replies)
Discussion started by: LAVco
2 Replies

6. Shell Programming and Scripting

Preserve output order when redirecting stdout and stderr

Hi, I already searched through the forum and tried to find a answer for my problem but I didn't found a full working solution, thats way I start this new thread and hope, some can help out. I wonder that I'm not able to find a working solution for the following scenario: Working in bash I... (8 Replies)
Discussion started by: Boemm
8 Replies

7. Shell Programming and Scripting

getting stderr & stdout output lively modified

This is about getting all output to stderr and stdout localized. Nothing to do with redirecting output to a file (there already are some interesting threads about that issue on this forum). What I intend to do is capturing all lines of text sent to the screen, compare them with an array of... (2 Replies)
Discussion started by: teo ramirez
2 Replies

8. UNIX for Advanced & Expert Users

sending syslog output to stderr or stdout

Is there a way to send the syslog output for a given facility to stderr or stdout? I do not want to use the "tail" command to achieve this, I would like it to go directly to stderr. Thanks in advance (1 Reply)
Discussion started by: dmirza
1 Replies

9. Shell Programming and Scripting

'tee' STDERR output (ksh)

Hi everyone, KSH question: I know you can 'tee' STDOUT to have the output go to multiple targets; can you do the same with STDERR? For example: ls |tee /tmp/file.txt Will redirect STDOUT to both the screen and the '/tmp/file.txt' file. Is there a way of doing the same thing for... (5 Replies)
Discussion started by: gsatch
5 Replies

10. Programming

stderr

in fprint(stderr, "lkjalsdi\n"); what does stderr mean? thanks (1 Reply)
Discussion started by: dell9
1 Replies
Login or Register to Ask a Question