Pages

Search This Blog

Total Pageviews

Tuesday, April 19, 2011

Traceroute shell script for linux/unix

Before you run the below script you need to save server list in /tmp/servlist. The below mentioned bash script you need to put in crontab to run as per the schedule. This script will send the traceroute whenever node/server is down. Please comment if this script is useful for you.


#!/bin/bash
#Author : Tejas Vino
#Purpose : To send the traceroute whenever server/node is down.
#Version : V1.0
#Date :April 19, 2011

Hostname=`/bin/hostname`
Trace="/bin/traceroute -I"

for i in `cat /tmp/servlist`
do
test=`fping $i | grep unreachable | awk '{print $1'}`
echo $test
if [ -z "$test" ]; then
sleep 1
else
$Trace $test | mail -s "$test is Down!!! Traceroute from $Hostname to $test" youremailid@domain.com &
fi
done

1 comment:

  1. You could use the positional parameters to make the script more dynamic.
    for i in `cat $1`

    Pls correct the syntax at
    awk '{print $1'}` to
    awk '{print $1}'`


    However you describe your topics very clearly, thx :)

    Pankaj Sain

    ReplyDelete