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

Re: Bash help



Stephen Carpenter <sjc@delphi.com> wrote:
| to make bash wait a certain amount of time...
| sleep(X) # X = number of seconds to "sleep"
| as for detecting an error....
| scripts can return errors just like any program...
| I think maybe hmmm I forget exactly how...but I know its no differnt than a
| program
| -Steve
| 
| BRIAN SCHRAMM wrote:
| 
| >      I am trying to tell if a program is passing back an error in a Bash
| >      script.  I would like to branch on receipt of the error to a wait
| >      statement that will give me about 20 seconds and then retry.
| >
| >      My trouble is I cannot remember how to detect the error and how to
| >      make the shell wait a definite amount of time.  Can anyone help me?
| >

You just need to check the return code of the program. This is stored
in the shell variable "$?". So

#!/bin/bash
your_program_here
if [ "$?" = "0" ]
then
  echo "Program successful"
else
  echo "Program unsuccessful"
fi

You have to rely on the fact that whoever wrote "your_program_here"
returns a non-zero status if the program fails.

The loop implementation is left as an exercise...

Gary


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


Reply to: