Capturing stderr in ksh script within a script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Capturing stderr in ksh script within a script
# 1  
Old 09-01-2011
Capturing stderr in ksh script within a script

I have seen lots of entries on stderr and stdout, but I did not see a solution to my question.

In running a script, I call another script. I want to capture output and error messages from the called script. I am able to redirect the stdout from the called script to my output file, but I don't seem able to capture the stderr portion.

Here is my line calling the script:

$READSCRIPT is the outside script I am calling.
$ERRFILE is a file name parameter I am passing to that script
$MAILFILE is the output file

When I run the script: sh -x tim_gap
Here is an example of an error message in the screen output:
gzcat: 00035146.20110829_-_2342+1900.gz: No such file or directory

However, when I look at my output file, $MAILFILE, the error message does not exist. I do capture the stdout messages into $MAILFILE. Am I using the proper syntax?

I appreciate any suggestions.

# 2  
Old 09-01-2011
You have to redirect it right when you run the command, not after the pipe. stderr doesn't pass through the pipe, it goes directly to the terminal.
# 3  
Old 09-02-2011
Thanks for the reminder.

Here is the code I ended up using so that I could keep the order of the message:
if [ -s $READERROR ]

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

STDOUT and STDERR redirection within a script

Hello all, I have a for loop executing in a script that I want to redirect STDOUT to screen and to file, while directing STDERR to the bit bucket. Here is the general sentax of what I'm doing: for i in thingy do some_command ${i} done 1>&1 | tee ${LOGFILE} 2> /dev/null What I am... (2 Replies)
Discussion started by: LinuxRacr
2 Replies

2. Shell Programming and Scripting

Writing to the stderr of a script

I have Mac OS X, and I wrote a bash shell script that does some encryption of files. When the user of the script does something wrong I want it to send an error message to the stderror of the script. Here's the code snippet I have: printf "$1: File not found\nNote: This script will only work... (6 Replies)
Discussion started by: Ultrix
6 Replies

3. Shell Programming and Scripting

Capturing log of a shell script

Hi, I have a script which does multiple tasks in sequence. When i execute the script, it runs and displays lot of messages for each of the steps on the console. Is there any way I can capture those messages and store it for audit purposes ? Best Regards, bornon2303 (2 Replies)
Discussion started by: bornon2303
2 Replies

4. Shell Programming and Scripting

Capturing SQL O/P in Unix Script

Hi, I would like to run a job based on the output from the SQL output. Eg: Select count(*) from A ...if count(*) = 1 then execute the next step or else exit. Please advise. Thanks S (2 Replies)
Discussion started by: pyaranoid
2 Replies

5. UNIX for Advanced & Expert Users

Truncation Occurs When Outputting Shell Script to stderr

Operating System: Solaris 10, Shell We are outputting the results of our scripts to the stderr file. However we have encountered a problem where some of the lines in the file are truncated. Is there a way to increase the terminal or column size within the script so that this does not... (4 Replies)
Discussion started by: fazzasx
4 Replies

6. Shell Programming and Scripting

Redirecting STDERR to a file from within a bash script

I am trying to redirect the output from stderr to a log file from within a bash script. the script is to long to add 2> $logfile to the end of each command. I have been trying to do it with the command exec 2> $logfile This mostly works. Unfortunately, when a read command requires that anything be... (5 Replies)
Discussion started by: vockleya
5 Replies

7. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

8. Programming

Capturing a ret val of C obj file in ksh script

Hi, I have one shell script which is calling a C executable. That C executable returns a value depending upon operations inside the C code. But how to get that value in the calling shell script? The syntax of calling the C executable is like -- C_exec <argc no> <argument1> <argument2> etc... (5 Replies)
Discussion started by: k_bijitesh
5 Replies

9. Shell Programming and Scripting

capturing output in script

I have the following line in my script: $sftpcmd $rmthost <<COMMANDS>> $sftplog 2>&1 For some reason this is not capturing the errors from sftp, they go to the file attached to the cron entry ie mm hh dd MM * /myscript > cron.out any idea why? digital unix 4.0d (6 Replies)
Discussion started by: MizzGail
6 Replies

10. Shell Programming and Scripting

stderr redirection in csh script

Man pages....look at the man pages. If you don't have them, you can find them on-line. Read them when you have nothing better to do. Find new commands and new ways of doing things. The answer: The only way to direct the standard output and standard error separately is by invoking... (0 Replies)
Discussion started by: thehoghunter
0 Replies
Login or Register to Ask a Question