Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

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 9:26:32pm UTC 

  1. #!/bin/bash
  2.  
  3. # a shell script that keeps looping until an exit code is given
  4.  
  5. # if it's a 0, immediatly restart
  6. # if it's an error, pause, then restart
  7. # and one particular code, exit cleanly.
  8.  
  9. ## Run the PHP script. What it returns decides on what happens next
  10. nice php -f cli-beanstalk-worker.php
  11. ERR=$?
  12.  
  13. ## Possibilities
  14. # 0    - unplanned restart (aka exit;)
  15. # 1-97 - unplanned restart
  16. # 98   - planned restart
  17. # 99   - planned stop, exit.
  18. # 100  - unplanned restart 
  19.  
  20. if [ $ERR -eq 97 ]
  21. then
  22.    # a planned pause, then restart
  23.    echo "PLANNED_PAUSE - wait 2";
  24.    sleep 2;
  25.    exec $0;
  26. fi
  27.  
  28. if [ $ERR -eq 98 ]
  29. then
  30.    # a planned restart
  31.    echo "PLANNED_RESTART";
  32.    exec $0;
  33. fi
  34.  
  35. if [ $ERR -eq 99 ]
  36. then
  37.    # planned complete exit
  38.    echo "PLANNED_SHUTDOWN";
  39.    #echo "sleep for a couple of secs first"
  40.    #sleep 2
  41.    #echo DONE, $$
  42.    exit 0;
  43. fi
  44.  
  45. # unplanned exit, pause, and restart
  46. echo "unplanned restart: err:" $ERR;
  47. echo "sleeping for (2) secs. - normally 10?"
  48. sleep 2
  49.  
  50. exec $0

Paste Details

Tags: bash loop

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



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.

comments powered by Disqus
worth-right
worth-right