0

I have a php script that works as long as the internet is on. When problems occur, it exits with code 1.

the code in windows looks like this:

:start php myScript.php IF %ERRORLEVEL% NEQ 0( ECHO "BAD EXECUTION, RESTARTING..." GOTO start) 

I am looking for the equivalent script for linux?

2
  • 1
    I hope you put a delay in there someplace because it things error that will do a lot restarting very quickly. Commented Mar 1, 2016 at 13:19
  • Possibly relevant: unix.stackexchange.com/questions/68175/… (use until) Commented Mar 1, 2016 at 13:28

1 Answer 1

2

It's about the same with the addition of sleeps in order not to create a fork bomb:

/* edited */ COMMAND="php myScript.php" SLEEPSEC=10 $COMMAND RC=$? while [ $RC -eq 1 ] ; do echo "BAD EXECUTION, RESTARTING..." sleep $SLEEPSEC $COMMAND RC=$? done 
4
  • "-eq: unary operator expected" on line 6 Commented Mar 1, 2016 at 13:58
  • What does the line: $COMMAND RC=$? do? Commented Mar 1, 2016 at 13:59
  • COMMAND="php 1.php" $COMMAND exitcode=$? SLEEPSEC=1 while [ $exitcode -eq 1 ] ; do echo "BAD EXECUTION, RESTARTING..." sleep $SLEEPSEC $COMMAND exitcode=$? done Commented Mar 1, 2016 at 14:21
  • I used that comment in the end. Thanks for the help! Commented Mar 1, 2016 at 14:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.