The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 08:43 PM
A script for shutdown kelu UNIX for Dummies Questions & Answers 12 08-23-2006 09:09 PM
Script not waiting for user responce rdudejr Shell Programming and Scripting 3 07-05-2006 11:20 AM
Shutdown script alpha_manic UNIX for Advanced & Expert Users 10 09-14-2005 04:14 PM
logout/shutdown script ropers UNIX for Dummies Questions & Answers 1 08-02-2002 02:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-07-2008
ringofsteel ringofsteel is offline
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?
  #2 (permalink)  
Old 01-07-2008
ringofsteel ringofsteel is offline
Registered User
  
 

Join Date: Jan 2008
Location: Sheffield, UK
Posts: 24
anyone?
  #3 (permalink)  
Old 01-07-2008
ajcannon ajcannon is offline
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
  #4 (permalink)  
Old 01-07-2008
ringofsteel ringofsteel is offline
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.
  #5 (permalink)  
Old 01-07-2008
porter porter is offline Forum Advisor  
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.
  #6 (permalink)  
Old 01-07-2008
ringofsteel ringofsteel is offline
Registered User
  
 

Join Date: Jan 2008
Location: Sheffield, UK
Posts: 24
Thanks! would this work with solaris 10?
  #7 (permalink)  
Old 01-07-2008
ringofsteel ringofsteel is offline
Registered User
  
 

Join Date: Jan 2008
Location: Sheffield, UK
Posts: 24
Il tell you the truth i dont really understand it

Yeah i can sort the root thing out i hope, how would i go abouts installing it?
Closed Thread

Bookmarks

Tags
ping, ping port, port, port ping

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:35 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0