Hello,
When I run a script, the script sometimes exited. I need to re-run it automatically again. Currently I am using crontab to run the script each 5 minutes. However, I need to have a better solution.
Any idea what to do?
thanks
Hello,
When I run a script, the script sometimes exited. I need to re-run it automatically again. Currently I am using crontab to run the script each 5 minutes. However, I need to have a better solution.
Any idea what to do?
thanks
quick Idea came on mind. could be better one. anyway you cna try this
call the script from another script and for value $?. if it failed, you can re-try 'n' times.
If your script sets exit codes (as, in an ideal world, should any process) it is not too hard to use a script wrapper:
First your_script.sh skeleton:
#! /bin/ksh
.... your code ....
if [ ... some condition ...] ; then
print - u2 "Houston, we have a problem. Aborting...."
exit 1 # aborted for some reason
fi
... more of your code ....
exit 0 # normal exit
Now the wrapper.sh skeleton:
#! /bin/ksh
while : ; do
your_script.sh # call your_script.sh
if [ $? -eq 0 ] ; then
break # exit the loop if your_script.sh finished normally
fi
done
exit 0
I hope this helps.
bakunin
hi melanie,
i guess your problem is that you want to make sure that your script is always running and you use the crontab to check if it does ?
As usual there is more that one way. If you need to be fast you can add this script to /etc/inittab very fast but if you are not root you can not do that.
Other wise the crontab is ok, check every minute (hour or what you need) if it is running.
pidof -x script >/dev/null || nohup script &