Clan x86

Technical (Development, Security, etc.) => Unix / Linux Discussion => Topic started by: Chavo on April 16, 2007, 11:03:04 AM

Title: Linux ERRORLEVEL equivalent?
Post by: Chavo on April 16, 2007, 11:03:04 AM
I have a simple script that I use to keep an application running on a windows machine:


:loop
;// execute a shell command
IF ERRORLEVEL == 1 GOTO loop
pause > nul


The program this is keeping alive I'm wanting to move to an offsite server that is running Linux.  Obviously I'll need to convert the script to something bash can understand, but the ERRORLEVEL variable is where I am lost.  ERRORLEVEL in Windows is a variable that holds the integer return value of the last command that executed.  For any normal program termination that is usually 0.  I have this particular program set to return 1 (System.exit(1)) when there is an error.  It logs the error on its own and this script restarts the program.  Anyone know the linux equivalent?
Title: Re: Linux ERRORLEVEL equivalent?
Post by: Skywing on April 16, 2007, 11:56:27 AM
Assuming you're using something compatible with /bin/sh, $? perhaps?
Title: Re: Linux ERRORLEVEL equivalent?
Post by: Chavo on April 16, 2007, 12:28:03 PM
yea


#!/bin/bash
# Simple keep-alive script

until (( ERRORLEVEL == 1 ))
do
  #start program
done

exit


Just need to figure out how to replace the ERRORLEVEL conditional
Title: Re: Linux ERRORLEVEL equivalent?
Post by: Skywing on April 16, 2007, 01:39:40 PM
That is what I was trying to tell you how to do (http://www.die.net/doc/linux/abs-guide/internalvariables.html#XSTATVARREF)...
Title: Re: Linux ERRORLEVEL equivalent?
Post by: Chavo on April 16, 2007, 02:48:55 PM
You'll forgive me if a question mark looks like a question ;)

That will work nicely, thanks.