The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk Shell Script error : "Syntax Error : `Split' unexpected Herry UNIX for Dummies Questions & Answers 2 03-17-2008 11:16 AM
error during run: St9bad_alloc - Getting this error while using some conversion progr sathu_pec Shell Programming and Scripting 1 01-21-2008 02:38 AM
I got error like...syntax error on line 1, teletype koti_rama UNIX for Advanced & Expert Users 2 07-07-2007 08:35 PM
error reading sections error at install doelman SUN Solaris 2 02-05-2007 12:21 PM
Error: Internal system error: Unable to initialize standard output file firkus UNIX for Dummies Questions & Answers 2 10-25-2005 04:23 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-19-2008
prismtx prismtx is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 24
Bypassing error in tar

I am tarring up a directory and then deleting the contents. I get a message that the file changed as tar was reading it, then my script fails on an error.

tar: /workdir/SRD.out.20080216: file changed as we read it
tar: Error exit delayed from previous errors

tar command failed, nothing archived - RC=0... message from my script.

The return code appears to be zero, but my script is not catching it and fails at that point without getting to the statement to delete the files. Any idea what I am doing wrong?

if ls $WORKDIR/* >/dev/null 2>&1; then
tar cvf $ARCH/logs.tar $WORKDIR
else
echo "No files to Archive"; exit 0;
fi
if [ "$?" -ge 1 ]; then echo "tar command failed, nothing archived - RC=$?..."; exit $?; fi
rm -f $WORKDIR/*
  #2 (permalink)  
Old 02-22-2008
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131

Code:
$ cat bogus
#! /usr/bin/ksh

false
echo $?
echo $?


false
if [ $? -ge 1 ] ; then echo but now the code is $? ; fi
$ ./bogus
1
0
but now the code is 0
$

$? is not the exit status of the last command you care about. It is the exit status of the last command. If you do anything except a comment $? may change. The [ in the if statement is a command. You use [ to test the tar command's exit status, then you display the [ command's exit status. Always do stuff like:
tar_status=$?
immediately after the tar command and then test and display the saved version.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0