The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shutdown script kingsto88 HP-UX 0 03-20-2007 05:43 PM
A script for shutdown kelu UNIX for Dummies Questions & Answers 12 08-23-2006 06:09 PM
Script not waiting for user responce rdudejr Shell Programming and Scripting 3 07-05-2006 08:20 AM
Shutdown script alpha_manic UNIX for Advanced & Expert Users 10 09-14-2005 01:14 PM
logout/shutdown script ropers UNIX for Dummies Questions & Answers 1 08-02-2002 11:05 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-07-2008
Registered User
 

Join Date: Jan 2008
Location: Sheffield, UK
Posts: 24
Help with script, shutdown if no ping responce

Hi, i would like to create a script that shuts down the system if the power fails, basicly the solaris box would load the script at startup.

Ping 192.168.1.100 every 20 secs
If cannot get responce 3 times in a row send init 0 to the system.

Simple but effective, as 192.168.100.1 wont be on the ups backup, so the solaris system will know the power is down and it will shutdown.

Im sure it wont be hard to do im just new to unix, could someone help me with this?
Reply With Quote
Forum Sponsor
  #2  
Old 01-07-2008
Registered User
 

Join Date: Jan 2008
Location: Sheffield, UK
Posts: 24
anyone?
Reply With Quote
  #3  
Old 01-07-2008
Registered User
 

Join Date: Aug 2007
Location: Binfield, Berkshire. UK
Posts: 91
Erm........

If I am reading this right.....you want to send a shutdown command to a machine, the power to which, has failed. If the power has failed the machine will be dead in the water and not be able to respond to *any* commands.

Have you described your requirement clearly and accurately as at present, unless I have badly misread it, it doesn't make a whole hep of sense
Reply With Quote
  #4  
Old 01-07-2008
Registered User
 

Join Date: Jan 2008
Location: Sheffield, UK
Posts: 24
I have a unix machine which is on a UPS with only about 15mins battery life, what i would like to happen is the unix machine shutdown safely if the power fails. The way i want to do it, would have the unix machine ping my cable modem every 20 secs, which is not on the UPS, so if the ping was to have no responce the modem would probably be off, which means the power would have failed.

I would like the unix machine to shutdown if it cant contact the cable modem 3 times in a row via ping.
Reply With Quote
  #5  
Old 01-07-2008
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Code:
#!/bin/sh

while true
do
      sleep 300
      REBOOT=/usr/bin/true
      for d in a b c
      do
            if /usr/sbin/ping cable-ip
            then
                 REBOOT=/usr/bin/false
                 break
            fi
      done
      if $REBOOT
      then
             shutdown -g 1 -y -i 5
      fi
done
or better still, remove outer while loop and install as cron job.

Note, Solaris "ping" works quite differently to other platform pings.
Reply With Quote
  #6  
Old 01-07-2008
Registered User
 

Join Date: Jan 2008
Location: Sheffield, UK
Posts: 24
Thanks! would this work with solaris 10?
Reply With Quote
  #7  
Old 01-07-2008
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Give it a go....

Make sure you understand it all before you install it, as it has to run as root to run shutdown.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0