Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ping and mail scripts 2

Status
Not open for further replies.

astin

MIS
Jun 20, 2002
87
GB
hi
I have looked at the past answers to requests for ping scripts and have tried to tailor them to my own needs but i havent had too much luck so far
so if anyone can help with this i would really appreciate it
i would like to run a script (on solaris) that reads a text file with info in the following format

glasgow_1 10.0.0.2
glasgow_3 11.0.0.2 etc...
note that the glasgow_1 names are NOT in dns. I would like the script to read the second column i.e. the ip address and go to a cisco router and ping it (using something like rsh).
then a second (pre-created) file would record the results. i.e. name (e.g. glasgow_1) and whether the ping succeeded or failed (even a line of .... or !!!!! would be good), finally im looking to have this file sent via email, i've tried mailx but i dont get the mail.
any help with this would be most welcome.
 
maybe something like:

for i in `cat $1 | awk {'print $2'}`;
do
ping -n 1 $i >> test.txt

done

the second script might use grep to check the ping result and use your command-line mailclient (like e.g. mutt) to send the mail.
there is some old ping around that just displays "glasgow is alive" what you can easily grep.

good luck.

regards
chenn
 
thanks chenn

but i am a bit confused, where do i reference the file in your script i.e. if my list of routers and ip addresses was called list.txt where do i reference it in the script ?

for i in `cat $1 | awk {'print $2'}`;
do
ping -n 1 $i >> test.txt

done
i see that the results would go to test.txt, i just am not sure how to reference the initial list of devices and ip's.
thanks
 
You need to replace the $1 with the name of the text file you mention here:
"would like to run a script (on solaris) that reads a text file with info in the following format"

$1 $2
glasgow_1 10.0.0.2
glasgow_3 11.0.0.2 etc.

Basically chenn says: for i in your file awk $2
then ping it and place the results in a file called test.txt.
 
thanks for the tip comtec
unfortunately I have tried the script and it still does not work :(
have you (or has anyone) a working example -or something similar that i could work from ? basically read the contents of a name - ip address list from one file - ping the ip, and record the name - and results in another file.

thanks
a
 
Can you post your text file here? Of course replace the addresses with dummy ones if you can.
 
Thanks comtec
its a standard text file

london 159.2.3.3
glasgow 159.3.3.3
moscow 172.16.7.4
st_paul 10.4.3.6
dallas 195.153.2.3
washington 207.8.5.4

so the ip addresses are field 2 i suppose
so i'd really like the script to ping the ip address then write to another file whether 'name' succeeded or failed.

i.e.
London passed
glasgow passed
moscow failed...
any help would be welcome.
thanks
 
thanks .
unfortunately it wont compile on my my solaris 2.6 box.
if anyone has any tips on gettting this to work without fping that would be appreciated.

thanks
 
astin,

Try something like the example below:

Code:
#!/usr/bin/ksh

>ping.out

for server in `cat server.list | grep -v ^# | awk '{print $2}'`

do ping $server > /dev/null
if [ $? -eq 0 ]
then
echo "`grep $server server.list | awk '{print $1}'` succeeded" >> ping.out
else
echo "`grep $server server.list | awk '{print $1}'` failed" >> ping.out
fi

done

cat ping.out
#mail report
mailx -s "Ping Status Report" user@domain.com < ping.out
 
thanks for your help john
i've tried this script - having put the devices in server.list

and i get the email. but it is blank

any ideas

thanks
astin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top