Paste Description for bash to keep a script looping
Depending on the exit() code, it will either restart, pause, then restart, or exit completely.
- bash to keep a script looping
- Sunday, February 8th, 2009 at 2:26:32pm MST
- #!/bin/bash
- # a shell script that keeps looping until an exit code is given
- # if it's a 0, immediatly restart
- # if it's an error, pause, then restart
- # and one particular code, exit cleanly.
- ## Run the PHP script. What it returns decides on what happens next
- nice php -f cli-beanstalk-worker.php
- ERR=$?
- ## Possibilities
- # 0 - unplanned restart (aka exit;)
- # 1-97 - unplanned restart
- # 98 - planned restart
- # 99 - planned stop, exit.
- # 100 - unplanned restart
- if [ $ERR -eq 97 ]
- then
- # a planned pause, then restart
- echo "PLANNED_PAUSE - wait 2";
- sleep 2;
- exec $0;
- fi
- if [ $ERR -eq 98 ]
- then
- # a planned restart
- echo "PLANNED_RESTART";
- exec $0;
- fi
- if [ $ERR -eq 99 ]
- then
- # planned complete exit
- echo "PLANNED_SHUTDOWN";
- #echo "sleep for a couple of secs first"
- #sleep 2
- #echo DONE, $$
- exit 0;
- fi
- # unplanned exit, pause, and restart
- echo "unplanned restart: err:" $ERR;
- echo "sleeping for (2) secs. - normally 10?"
- sleep 2
- exec $0
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.