Getting error return code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting error return code
# 1  
Old 10-24-2009
Getting error return code

I need to try and get the error return code from the tar command when being used as follows:

tar tvf tarfile 2>logfile | tee -f outputfile
ErrorStat="$?"

I would like to save the error return code from the tar command in a variable,
howver, the example above it is saving the 'tee' error status.

Is there a way to save the 'tar' error code or maybe a better way to utilize the 'tee' command?
# 2  
Old 10-24-2009
What you are getting here is the return code from the tee command.

Redirect the file using > instead of tee.

(don't know what the -f option of tee does)
# 3  
Old 10-24-2009
Well, my purpose for using tee was that I wanted the output to go to the screen as well as a log file.
# 4  
Old 10-24-2009
Code:
mknod output.txt p

cat output.txt | tee log.txt &

tar cvf test.tar comm comm2 file21 > output.txt
RETCODE=$?

sleep 1

echo $RETCODE

rm output.txt

Your output is in log.txt
# 5  
Old 10-24-2009
In more recent versions of bash and ksh you can do this:
Code:
set -o pipefail
tar tvf tarfile 2>logfile | tee -f outputfile
ErrorStat="$?"
set +o pipefail

# 6  
Old 10-24-2009
Nice one.

Was using ksh on Solaris, which doesn't have this as I can see, but the bash does.
# 7  
Old 10-24-2009
Code:
TMPF=/tmp/tar-rc.$$.$RANDOM
(tar tvf tarfile 2>logfile;echo $? >$TEMF) | tee -f outputfile
ErrorStat="$(<$TMPF)"; rm $TMPF

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error re-direction and Return code

Hi, I have a shell script which executes some sql. When the shell script executes the sql's logging is shown on the console. I need to grep some data from this output shown on console. So I do the following hive -f load.adj.hql 2>&1 | tee c.txt echo $? A=`grep num_rows c.txt` $? will... (1 Reply)
Discussion started by: wahi80
1 Replies

2. Shell Programming and Scripting

Greping return code error

Hi folks, I am running below code which is giving me output "httpd (no pid file) not running", how can i grep this code in shell script. I have tried below code but it is not giving me error in echoing. ./webserver stop if echo " Everything is OK" else echo "Error code $0... (4 Replies)
Discussion started by: learnbash
4 Replies

3. UNIX for Dummies Questions & Answers

Does SCP return an error code for network issues

Hello everyone, In a script, I am using SCP to copy huge file to another host. scp -qrp hugefile.txt /opt/perf05/tmp However, we have noticed that this file is not being copied. I am suspecting this was because we are losing connection while copying this... (1 Reply)
Discussion started by: qwarentine
1 Replies

4. Shell Programming and Scripting

SFTP return Error Code 126

Hi, We are getting the following error code while connection remote server using sftp command. sftp user@serrver Warning: child process (/opt/ssh2/bin/ssh2) exited with code 126. pls Advise. (2 Replies)
Discussion started by: koti_rama
2 Replies

5. UNIX for Dummies Questions & Answers

Command 'rm -f -r "0yfOYy-0008Nq-2j-32233-K"' failed with return code 1 and error mes

I would like to know what means this error and how to fix it Command 'rm -f -r "0yfOYy-0008Nq-2j-32233-K"' failed with return code 1 and error message Thank you (3 Replies)
Discussion started by: linuxbee
3 Replies

6. Shell Programming and Scripting

return code help

Hello folks, I have a question that if i type ls command and type echo $? it always show "0", how i could do this change that when i type ls it will show me 1, actually i want to change the return code of commands from 0 to 1. Thanks Bash (5 Replies)
Discussion started by: learnbash
5 Replies

7. Shell Programming and Scripting

Need help with return code 1...

Hi Guys,, I am having a unix script which is running the DB2 Insert command. For the insert command, there were no records to be updated. SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table. SQLSTATE=02000 + + echo 1 STAGE_RC=1 + ] ... (6 Replies)
Discussion started by: mac4rfree
6 Replies

8. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

9. Shell Programming and Scripting

how to get error return code

I have a unix AIX script that ftps some files (mput, mget). How can I check (in the script) to see if the ftp failed? After the ftp I move the files out of the directory but do not want to move files that have not been sent. The script will run as a cron job. (2 Replies)
Discussion started by: rayg50
2 Replies

10. UNIX for Advanced & Expert Users

Return code from PL/SQL Code

Hi Guys, I was just wondering if anybody can help me with this problem. OK, how we can get a value back from PL/SQL Script (not stored procedure/function) See the below example: (for example aaa.sh) #!/bin/ksh VALUE=`sqlplus -s user/password@test_id <<EOF @xxx.sq EOF` echo $VALUE ... (7 Replies)
Discussion started by: Shaz
7 Replies
Login or Register to Ask a Question