Re: [Nolug] Bash backup script help

From: B. Estrade <estrabd_at_gmail.com>
Date: Sat, 23 Jun 2007 09:01:25 -0700
Message-ID: <a7ee76680706230901y5b4bb91bqc2d3716fd18e4c6f@mail.gmail.com>

Chris,

You could also use "&&" and "||"

% cmd1 ... && cmd2
% cmd1 ... || cmd2

"&&" executes the second command only if the one before it returns a
successful exit status; "||" executes the second command only if the
first one succeeds.

Real world example; initially the directory 'test' does not exist:

$ cd test 2> /dev/null || (mkdir test && touch test/test.dat)

Or in your case:

#!/bin/sh
tar .. || exit 1
echo hi # this will not print if tar fails

B

On 6/22/07, Chris Jones <techmaster@gmail.com> wrote:
> Thanks, I just figured it out before I checked my email. ;) Works great as
> far as I can tell, now I've just got to wait till this weekend to try
> shutting down vmware and backing it up.
>
>
> On 6/22/07, -ray <ray@ops.selu.edu> wrote:
> > On Fri, 22 Jun 2007, Chris Jones wrote:
> >
> > > The functionality I'm wanting to add to it, is after the TAR/GZIP
> operation,
> > > I want it to know if the tar command completed successfully or with
> errors.
> > > If there were errors, then skip the deletion process. The skipping part
> is
> > > easy, but I guess the main thing I'm wondering is how do I test whether
> the
> > > tar command ran successfully? I remember in DOS, after you run a
> command,
> > > you can test it with "IF ERRORLEVEL=0" and if that returns true then you
> > > know the command completed successfully. What's the unix equivalent?
> >
> > It's similar in unix, using the $? variable. Most commands will exit
> > non-zero status if there's a problem, and exit zero status if there's no
> > problem. Based on this, run this code immediately after the tar command:
> >
> > if [ $? != 0 ]; then
> > echo "tar exitted non-zero. Let's not delete"
> > exit 1
> > fi
> >
> > ray
> > --
> >
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> > Ray DeJean
> http://www.r-a-y.org
> > Systems Engineer Southeastern
> Louisiana University
> > IBM Certified Specialist AIX Administration, AIX Support
> >
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> >
> > ___________________
> > Nolug mailing list
> > nolug@nolug.org
> >
>
>

-- 
225.578.1920
AIM: bz743
http://www.loni.org/
estrabd@lsu.edu
estrabd@gmail.com
___________________
Nolug mailing list
nolug@nolug.org
Received on 06/23/07

This archive was generated by hypermail 2.2.0 : 12/19/08 EST