Re: [Nolug] Bash backup script help

From: B. Estrade <estrabd_at_gmail.com>
Date: Sat, 23 Jun 2007 13:17:37 -0700
Message-ID: <a7ee76680706231317q4957fc14me68100adb6c19f0@mail.gmail.com>

You test if something like:

ps -auxw | grep name_of_exe

returns a non-empty string, though this is probably not the best way
to test if a program is running. I am not really sure what is...anyway

so doing what you want to do would look something like:

if [ -n `ps -auxw | grep name_of_exe` ]; then
  echo "name_of_exe is in the ps output"
else
  echo "name_of_exe not found in ps output"
fi

Hope that helps.

Brett

On 6/23/07, Chris Jones <techmaster@gmail.com> wrote:
> One more thing I thought of... I set this script up as a crontab to run at
> 11pm every night. I'm thinking of making another script as a watchdog, to
> run at maybe 1am, to make sure it's running. Here's what I've got so far,
> and the output it gives me:
>
> /etc# /etc/init.d/vmware status | grep "VMware Server"
> At least one instance of VMware Server is still running.
>
> How can I test that in an if statement?
>
>
> On 6/23/07, B. Estrade <estrabd@gmail.com> wrote:
> > doh! sorry;
> >
> > > "||" executes the second command only if the first one succeeds.
> >
> > I meant "only if the first one FAILS". Sorry.
> >
> > B
> >
> > On 6/23/07, B. Estrade < estrabd@gmail.com> wrote:
> > > 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
> > >
> >
> >
> > --
> > 225.578.1920
> > AIM: bz743
> > http://www.loni.org/
> > estrabd@lsu.edu
> > estrabd@gmail.com
> > ___________________
> > 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