rerun a script if aborted and exited


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users rerun a script if aborted and exited
# 1  
Old 02-21-2008
rerun a script if aborted and exited

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
# 2  
Old 02-21-2008
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.
# 3  
Old 02-21-2008
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:
Code:
#! /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:

Code:
#! /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
# 4  
Old 02-21-2008
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 &
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

./deinstall: Exited from program error

I am wondering if I can get some help here. I am deinstalling Oracle home on solaris. Downloaded deintsall zip file from oracle and then ran ./deinstall -home (Full Path) 10 seconds later I get this: Any idea how to resolve this issue? $ ./deinstall -home... (4 Replies)
Discussion started by: newborndba
4 Replies

2. Red Hat

RHEL6 : Remote process exited without returning status

Hi All, I am using RHEL 6 linux in my lab server and I am new to RHEL6 features. lab1:root> uname -a Linux lab1 2.6.32-358.18.1.el6.x86_64 #1 SMP Fri Aug 2 17:04:38 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux I am facing a peculiar issue in my lab machine. When I connected via Opsware Global... (0 Replies)
Discussion started by: go2suresh1979
0 Replies

3. UNIX for Dummies Questions & Answers

Remotely close & rerun SSH connection

I'm trying to remotely run an upgrade script (via SSH) that update the SSH script on several hosts, just need to add several flags for the ssh command to look like this: ssh -Nf -i id_logs -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -o ServerAliveInterval=60 -o ServerAliveCountMax=5... (4 Replies)
Discussion started by: OdedOvdat
4 Replies

4. Solaris

backup aborted

hi all I am getting following error while taking backup using the command ufsdump 0ubf 512 /dev/rmt/0cbn /database/backup2/rman_backup/level0 >> /database/backup2/backup_tape/level0_rman_06sep12 2>&1; from the log i got the error bash# tail -f level0_rman_06sep12 DUMP: Date of... (3 Replies)
Discussion started by: nikhil kasar
3 Replies

5. UNIX for Dummies Questions & Answers

WARNING: init(1M) exited on fatal signal 9: restarting automatically

Have you ever got these : WARNING: init(1M) exited on fatal signal 9: restarting automatically and how did you solve it? (3 Replies)
Discussion started by: anaABB
3 Replies

6. Shell Programming and Scripting

Rerun a cronjob if it doesn't work at first.

I want to add a line to the script that searches for a file. If the file does not exist, I need to kill the cronjob and run it again in one hour. I am running the program and 2 am and 2pm. I would want the job to run again at 3am and 3pm respectively. How could I do this and still keep the cronjob... (1 Reply)
Discussion started by: libertyforall
1 Replies

7. Shell Programming and Scripting

Automatically Rerun a script based on previous execution output

Hi Experts, I have a shell script called "updatevs" that is scheduled to run at 6.00 am everyday via cronjob. The cronjob will execute this script and output to a log file. The functionality of this script is to read the database and run a set of commands. This script is generally successful... (6 Replies)
Discussion started by: forumthreads
6 Replies

8. Shell Programming and Scripting

Rerun sql statement

Hi, Script that I wrote only run sql query once then exit. But my requirement, I want the query can be execute a couple of time without exiting the script. How could I do it? Thanks. (1 Reply)
Discussion started by: killboy
1 Replies

9. Programming

Program exited with code 01: does it indicate unsuccessful compilation?

(gdb) r --------------------- enter Breakpoint 1, 0x0000000000409d40 in main () (gdb) n Single stepping until exit from function main, which has no line number information. Find_Cmd_Option: found option no. 2: seed (s) Find_Cmd_Option: found option no. 5: dfile (c) Initial no. div... (1 Reply)
Discussion started by: cdbug
1 Replies

10. AIX

rerun .profile after changing variable

I changed a $variable in my .profile (AIX unix). I know I could exit out and logon onto unix again, but how do I rerun the .profile at the command line? (2 Replies)
Discussion started by: sboxtops
2 Replies
Login or Register to Ask a Question