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

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
  • "-eq: unary operator expected" on line 6 – Ted Mar 1 '16 at 13:58
  • What does the line: $COMMAND RC=$? do? – Ted Mar 1 '16 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 – Ted Mar 1 '16 at 14:21
  • I used that comment in the end. Thanks for the help! – Ted Mar 1 '16 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.