Author Topic: Linux ERRORLEVEL equivalent?  (Read 28828 times)

0 Members and 1 Guest are viewing this topic.

Offline Chavo

  • x86
  • Hero Member
  • *****
  • Posts: 2219
  • no u
    • View Profile
    • Chavoland
Linux ERRORLEVEL equivalent?
« 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:

Code: [Select]
: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?

Offline Skywing

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • Nynaeve
Re: Linux ERRORLEVEL equivalent?
« Reply #1 on: April 16, 2007, 11:56:27 am »
Assuming you're using something compatible with /bin/sh, $? perhaps?

Offline Chavo

  • x86
  • Hero Member
  • *****
  • Posts: 2219
  • no u
    • View Profile
    • Chavoland
Re: Linux ERRORLEVEL equivalent?
« Reply #2 on: April 16, 2007, 12:28:03 pm »
yea

Code: [Select]
#!/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
« Last Edit: April 16, 2007, 12:30:55 pm by unTactical »

Offline Skywing

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • Nynaeve
Re: Linux ERRORLEVEL equivalent?
« Reply #3 on: April 16, 2007, 01:39:40 pm »

Offline Chavo

  • x86
  • Hero Member
  • *****
  • Posts: 2219
  • no u
    • View Profile
    • Chavoland
Re: Linux ERRORLEVEL equivalent?
« Reply #4 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.