Auto restart script does not work


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Auto restart script does not work
# 1  
Old 01-04-2011
Auto restart script does not work

I have a service that are not 100% stable and stops from time to time.
So I have a script that do restart the service if it does not run.

This script works win on Ubuntu 9.04 but will not start the service in Ubuntu 10.10

If I run the part that do starts the service from CLI, it starts normal.
Any idea of what is wrong?

This runs fine manually
Code:
/var/bin/Server.x86 &

Script
Code:
#!/bin/sh
date=`date`
echo "-------------------------------------------------"  >> /var/bin/checksvc.log   
echo "Restarting Server : $date" >> /var/bin/checksvc.log
echo "-------------------------------------------------"  >> /var/bin/checksvc.log

while [ 1 ] 
do
pidof Server.x86 >/dev/null
if [ $? -eq 0 ] ; then
echo ""
else
date=`date` 
echo "Restarting CCcam : $date" >> /var/bin/checksvc.log
/var/bin/Server.x86 &
  if [ $? -eq 0 ] ; then
    echo "ok!"
      else
        echo "hm, didn't work. Try doing it manually"
          fi 
          fi
          sleep 30
          done

# 2  
Old 01-05-2011
What shell you are using for command line execution? probably its different from "/bin/sh".
and you are not getting the proper environment to run the command successfully.

try replacing this line :

Code:
/var/bin/Server.x86 &

with :
Code:
/var/bin/Server.x86  >> /var/bin/checksvc.log 2>&1 &

So that you can get some error msg (if any) in the log file.

also, check your working shell with echo $0 on the command line and run the script in that shell.
This User Gave Thanks to clx For This Post:
# 3  
Old 01-05-2011
Thanks, you are my man
echo $0 did show bash, sames as ps listed
Changing script to #!/bin/bash did solve my problem
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to auto restart java for 100 percent

I want the tomcat to restart when java goes 100% cpu utilize and remain on this , Get pid kill and start tomcat . top | grep java We can get pid and cpu utilize , But how can we do on run time. Please use code tags as required by forum rules! (1 Reply)
Discussion started by: kaushik02018
1 Replies

2. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

3. Shell Programming and Scripting

My script work on Linux but not work in sunos.

My script work on Linux but not work in sun os. my script. logFiles="sentLog1.log sentLog2.log" intial_time="0 0" logLocation="/usr/local/tomcat/logs/" sleepTime=600 failMessage=":: $(tput bold)Log not update$(tput rmso) = " successMessage="OK" arr=($logFiles)... (7 Replies)
Discussion started by: ooilinlove
7 Replies

4. UNIX for Advanced & Expert Users

Opinion on auto-restart of failed apps/services

I'm becoming a dying breed where I work. More and more sys admins are advocating automatically restarting failed services such as tomcat, jboss, etc. I've always been against doing this except with buggy apps that can't be fixed or avoided. My main argument is that I feel it's a trick used by... (9 Replies)
Discussion started by: mglenney
9 Replies

5. Shell Programming and Scripting

How to restart a script?

Hello, I created a shell script in /etc/init.d and it already runs at boot. However I cannot figure out how to make it run just like typing "scrip_name start" I can run it like this ./script_name but since I am doing remote log in whenever I log off the script stops and I also don't want to run... (8 Replies)
Discussion started by: kizofilax
8 Replies

6. HP-UX

Script to auto restart a service

Hi All, May i please know if it is possible to write a script to check the log messages and automatically restart a service if it is failed or it is stopped. Appreciate your suggestions. Thanks in advance. regards, Eajaz (2 Replies)
Discussion started by: ajazshariff
2 Replies

7. Solaris

Auto Start/Stop Didnt Work in Solaris 10

Hi...all database - 10g Rs 2 with ASM platform - Sun Solaris V890 64bit This is the step i use to auto start the database n ASM: (auto start can start but need to kill lsvcrun first) 1 dbora---script 2 start_shutdown_asm.ksh---script 3. Dbora file must be put under /etc/init.d directory... (0 Replies)
Discussion started by: adzuanamir
0 Replies

8. UNIX for Dummies Questions & Answers

Restart Script

Hi, I am writing a script and need to goto the start of the script if an incorrect command is wrongly entered what can i do. Andy (1 Reply)
Discussion started by: chapmana
1 Replies

9. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

10. Shell Programming and Scripting

Auto Detection/Restart of Sybase Deadlocks

Does anyone have an example of a ksh script that executes a Sybase stored procedure, via the ISQL command, and can detect a deadlock and loop until the process completes successfully? I'm a little confused on where to start. Thanks in advance for any assistance you can provide. (0 Replies)
Discussion started by: BCarlson
0 Replies
Login or Register to Ask a Question