I have a simple bash script which calls a php script every 10 minutes thats performs some maintenance. Every once in a while this php script terminates while it’s running and when this happens the bash script exits.
I’d like to make it so the bash script keeps on looping even if the php script falters. Can anyone point me in the right direction? I’ve been searching for a while but I can’t seem to find the answer, maybe I’m not using the right search terms.
#!/bin/sh
set -e
while :
do
/usr/bin/php /path/to/maintenance/script.php
sleep 600
done
The:
line sets the shell’s “exit on error” flag, which tells it that if a program it runs exits with a non-zero status, the shell should also exit:
There are exceptions for programs whose status is being tested, of course, so that:
will work correctly (one or or the other echo will occur, and then the last one will as well).
Back in the Dim Time, when
/bin/shwas non-POSIX and was written in Bournegol, there was a bug in some versions ofshthat broke||expressions:(The logic bug applied to
&&expressions internally as well, but was harmless there, sincefalse && anythingis itself false which means the whole expression fails anyway!) Ever since then, I’ve been wary of “-e”.