RabbieBurns (21st January 2010)

Ive got a server that runs a runs a script on the hour. Trouble is said server is a bit prone to the occasional lockup or crash etc and sometimes the script wont run untill I can get someone to reboot the server..
Got a backup server that runs, that isnt really capable of running the script regularly but could cope with it for a couple of days.. I was wondernig if there was a wayh of running a script on the backup server to do the following
Check main server is replying to ping
if OK do nothing
if no ping, run the script locally
Both machines are gentoo linux so a perl / bash / python or whatever would be fine to run
Any ideas would be appreciated.. cheers..

Have something in VB but don't think that will help you.
This looks like a BASH script that would do it.
Got it from hereCode:#!/bin/bash # Simple SHELL script for Linux and UNIX system monitoring with # ping command # ------------------------------------------------------------------------- # Copyright (c) 2006 nixCraft project <http://www.cyberciti.biz/fb/> # This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # ------------------------------------------------------------------------- # Setup email ID below # See URL for more info: # http://www.cyberciti.biz/tips/simple-linux-and-unix-system-monitoring-with-ping-command-and-scripts.html # ------------------------------------------------------------------------- # add ip / hostname separated by white space HOSTS="cyberciti.biz theos.in router" # no ping request COUNT=1 # email report when SUBJECT="Ping failed" EMAILID="me@mydomain.com" for myHost in $HOSTS do count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }') if [ $count -eq 0 ]; then # 100% failed echo "Host : $myHost is down (ping failed) at $(date)" | mail -s "$SUBJECT" $EMAILID fi done
UNIX / Linux Shell Script For Monitoring System network with ping command
I Googled perl ping and got this:
Net::Ping - perldoc.perl.org
The example script shows how to use it.
Then, to launch a script if there's no ping, try:
exec - perldoc.perl.org
Then you could cron your "pinging" script to run it every minute, hour, day, specific time etc...
how about these?
and found thisCode:#!/bin/bash if ping -c 1 4.2.2.2 then : # colon is a null and is required else **** your command here **** fi
in an old script of mine, cant remember where it came from tho.
this one would detect if the link was dropping some of the packets
BoXCode:#!/bin/bash while [ -n "$(ping -c 1 192.168.0.1|grep 100%)" ] do : # colon is a null and is required else **** your command here ****
Last edited by box_l; 21st January 2010 at 08:06 PM.
RabbieBurns (21st January 2010)

There are currently 1 users browsing this thread. (0 members and 1 guests)