Simple Ping script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Simple Ping script
# 1  
Old 05-18-2010
Simple Ping script

Hi there

i am busy compiling a script to ping a remote server, when the server is alive i get it to send me an sms, however i cant seem to make the ping stop, can somebody please help? please?

Code:
while (9)
    set ans="`ping $IPaddress 1`"
    if ( "$ans" == "IPaddress is alive" ) continue             
    sleep 5
    echo "is alive"
end  
echo out of loopp. my script that i have created is below.

Kind regards...

brian

Last edited by pludi; 05-18-2010 at 04:43 AM.. Reason: code tags, please...
# 2  
Old 05-18-2010
Code:
ping -n 3 -i IP_ADDRESS

Check in:

Code:
man ping


Last edited by haaru; 05-18-2010 at 04:54 AM..
# 3  
Old 05-18-2010
thank you, but this needs to continually ping until the server is up. then once it comes up (say 3am), i dont really want it to continually sms me every 5 seconds till i get to work. i just need to know that the network connection has been reastablished and for the script to them stop running? kind regards
# 4  
Old 05-18-2010
add the ping in loop

Code:
i=2
while [ $i -eq 2 ];do

ping -c 2 172.21.142.108
 if [[ $? == 0 ]]

then
echo "server up"
i=0
else
echo "server down"
fi
done

# 5  
Old 05-18-2010
You can schedule it in crontab so that the script runs every minute or so. Do a

Code:
man crontab

to see how it works.

As far as the 'not sending sms with error continually' you can have your script write a log every time the server is checked.
Then just before pinging, the script should read the last line of the log

Code:
cat log | tail -1

  • If the last line is Error and the server is still down do nothing.
  • If the last line is Success and the server is down send 'Warning' SMS
  • If the last line is Error and the server is up send 'Server is up' SMS

This is the first thing that come into my mind. Maybe someone has a better idea.
If you do something like this, do not forget to clear the log every so often!! Smilie
# 6  
Old 05-18-2010
thanks guys, it works
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Ping test sends mail when ping fails

help with bash script! im am working on this script to make sure my server will stay online, so i made this script.. HOSTS="192.168.138.155" COUNT=4 pingtest(){ for myhost in "$@" do ping -c "$COUNT" "$myhost" &&return 1 done return 0 } if pingtest $HOSTS #100% failed... (4 Replies)
Discussion started by: mort3924
4 Replies

2. Shell Programming and Scripting

Script with ping

I have a question is there any posibility for writing a script that you can see if a pc in your network is up of down , when you run this script for ex. ./test.sh 63 45 54 , which are the ip adresses of the computers , when you give the last digit of the ip adres as argument 63 , 45 and 54 are... (5 Replies)
Discussion started by: Roggy
5 Replies

3. Shell Programming and Scripting

ping script

hello fellows, I need help with a script, I'm using this one HOSTS="192.168.10.9 192.168.10.15 " SUBJECT="Attention - Gateway San Martin DOWN " COUNT=1 EMAILID="lmail@mydomain.com" for myHost in $HOSTS do count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2... (2 Replies)
Discussion started by: lucas.fradusco
2 Replies

4. Shell Programming and Scripting

Need bash script to ping the servers and rename the output file each time the script is ran

HI, I have a file serverlist in that all host names are placed. i have written a small script #./testping #! /bin/bash for i in `cat serverlist` do ping $i >> output.txt done so now it creates a file output.txt till here fine.. now each time i run this script the output file... (4 Replies)
Discussion started by: madhudeva
4 Replies

5. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

6. Shell Programming and Scripting

Using ping in script

Hi. I have a server with multiple network ports that need to be tested to a list of destinations. I'm trying to write a scripts to automate this but can't seem to get past an error and could use some help. I have two test files one contains the ip addresses of the onboard NICs and the other... (10 Replies)
Discussion started by: mikez104
10 Replies

7. Shell Programming and Scripting

Animation Ping on Solaris Like Cisco Ping

Hi, I develop simple animation ping script on Solaris Platform. It is like Cisco ping. Examples and source code are below. bash-3.00$ gokcell 152.155.180.8 30 Sending 30 Ping Packets to 152.155.180.8 !!!!!!!!!!!!!.!!!!!!!!!!!!!!!. % 93.33 success... % 6.66 packet loss...... (1 Reply)
Discussion started by: gokcell
1 Replies

8. Shell Programming and Scripting

Help With Ping Script

Hello all...I'm new to Unix and learning. What I'm trying to create is a script that will ping a known range of IP addresses, say 192.168.1.1 to 192.168.1.254. For each address that no reply is received, that address will be written to a log file that will be emailed to an administrator. My wife... (1 Reply)
Discussion started by: spmitchell
1 Replies

9. Shell Programming and Scripting

Need a Simple ping script

Hi, I am a learner in shell scripting. Can someone help me in getting a script to run the ping command in the background through a script to get the status of my servers and email me if ping failed with list of servers in one email. Thanks (4 Replies)
Discussion started by: bachusunil
4 Replies

10. Shell Programming and Scripting

Ping Script

hello, I am looking to make a script that will ping a remote ip address. Upon completion of the ping I want the program to either ping again if the # of packets transmitted is equal to the number of packets received or exit if the two values are unequal and information was lost. I am not sure if I... (3 Replies)
Discussion started by: mcrosby
3 Replies
Login or Register to Ask a Question