[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Question with $? in bash, with chains of commands



Here's a code fragment i'm trying to work on in bash

I'm pulling a backup, and if smbtar aborts for whatever reason, I need
to know not to rotate the backup.

smbtar -s $username -x $share -p $password -t - | gzip -1 > $filename.tar.gz
if [ $? -eq 0 ]; then
        # rotate the backup;
fi;
	# else go on to the next machine

The problem is, $? reports the result of the last command, which is gzip,
which will ALWAYS report 0(well, unless the hd is full or the moon is
full), because smbtar spits out data to it.  If I remove the gzip -1, it
works as expected.

I need to gzip on the fly, because smbtar doesn't a) support compression,
and b) 2gb filesize limits and these workstations are over 2gb in some
cases, and c) disk space isn't free.  If it wasn't for b) I'd gzip after a
backup is done.

Anyone have any ideas?  My current method is to check if the backup is
over a predefined size, but that doesn't work if the backup crashed over
that size), so I'm trying to do it properly.

Mike


-- 
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org



Reply to: