help: infinant loop script - host ping test


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help: infinant loop script - host ping test
# 1  
Old 04-23-2007
help: infinant loop script - host ping test

need to check on some hosts and send an email if there status changes

I wanna put together a script in bash that will allow me to check the up/down state of a single host via ping

i want it to run in a continuous loop so I can just fire the script and forget about it(dont want cron to drive the script), if the host is up..then just keep pinging until its down.

At that point i want it to ping about 4 more times just ensure its not a network glitch, and if its still down send me an email. from there just keep pinging until its back online and then send me an email to let me know its up

seems easy right? not when you actually have to sit down and write (at least for me)

I've got coders block, cant seem to figure out what logic i can use to figure this out --i've been writing tons of functions and array, but am having no luck tieing them together


any help would be so very very appreciated
Tks
# 2  
Old 04-23-2007
You could use this logic:
keep pinging as long as there is a response
if there is no response, ping four times
if still no response, send an alert, otherwise start pinging again.
# 3  
Old 04-23-2007
an awk example, not including infinite pinging.
Code:
#!/bin/bash
awk '	function pinger(count,ip) {
		command = "ping -c "count " " ip		
		while (( command | getline res )> 0 ) {	
			if ( res ~ /0 received|100% packet loss/ ) {
				close(command)
				return 100			 
			}
		}
	close(command)
	return 0
	}	
	BEGIN { 	
	IP="x.x.x.x"	
	if ( pinger(2,IP) == 100 ) {
		print IP " Not up"
		c = 0
		while ( c < 4 ) {			
			if ( pinger(2,IP) == 100 ) {
				print IP " Not up yet" 
			}
			c=c+1
		}
	} else { print IP " up" }
}'

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

Ping Response from the host name

Hi All, I have the requirement where am pinging the server and matching the IP address with the existing IP address. Below code is returning me the IP address and my requirement is i have to see that also whether it is pinging or not PING useipapd01 (172.22.32.87) 56(84) bytes of data. 64... (1 Reply)
Discussion started by: sharsour
1 Replies

3. Shell Programming and Scripting

Ping Host Until it is up and email

Hi I am trying to write a script which runs until the host is up. i got it figured out that it needs to be in loop till it return $? = 0. Not getting it through though. I am not sure about the 6th line !!! #!/bin/sh HOSTS="host.txt" ping(){ for myhost in "$HOSTS" do ping -c -1 "$myhost"... (8 Replies)
Discussion started by: Antergen
8 Replies

4. IP Networking

ping can not recognize host but host command can

Hi, I have a weird problem. when ever I do ping command like for example ping unix.comI get the following message: # ping unix.com ping: unknown host unix.com but when I use host the computer is able to know the host. # host unix.com unix.com has address 81.17.242.186 unix.com mail is... (2 Replies)
Discussion started by: programAngel
2 Replies

5. Solaris

Unable to ping Solaris VM from Xp host

Hi All, I am using Vmware Workstation 6.0.3 build-80004. Guest OS: Solaris 10 Host OS : Win XP I am getting request time out when i am trying to ping from XP ( cmd line) to Solaris VM - I have assigned IP 192.168.50.5 in Solaris VM ( Hostname: Tower1) and it is in UP status. ... (4 Replies)
Discussion started by: saurabh84g
4 Replies

6. UNIX for Dummies Questions & Answers

PING to one host in one background process

Hi All, I'm doing one script on Juniper router where you have one FreeBSD Shell: Is pinging from time to time one ethernet port of othere router and in case of fail is blocking one port entering in CLI and doing some command: If I run this script all is working perfectly, but if I run in... (1 Reply)
Discussion started by: teigipo
1 Replies

7. Solaris

PING - Unknown host 127.0.0.1, Unknown host localhost - Solaris 10

Hello, I have a problem - I created a chrooted jail for one user. When I'm logged in as root, everything work fine, but when I'm logged in as a chrooted user - I have many problems: 1. When I execute the command ping, I get weird results: bash-3.00$ usr/sbin/ping localhost ... (4 Replies)
Discussion started by: Przemek
4 Replies

8. Shell Programming and Scripting

help to ping a host, is it alive or not ...

hello to everyone, i was wondering if you could help me with a script im working on, it's kind of simple but i dont have a lot experience on unix comands: well, here it is: you might apreciate the infinite while loop :D, it is supossed to be running on the server all day scaning it every 5... (12 Replies)
Discussion started by: sx3v1l_1n51de
12 Replies

9. IP Networking

QNX host cannot ping SCO host, vice versa

The problem I am facing now is that the QNX host could not ping the SCO host and vice versa. They are in the same domain, ie, 172.20.3.xx. As I am very new to Unix, I guess I must have missed out some important steps. Pls help... Thanx alot (2 Replies)
Discussion started by: gavon
2 Replies

10. UNIX for Dummies Questions & Answers

Unable to ping host

Hi, dear all, I am rather new to Unix and have this problem where I cant seem to ping from 1 host to another. The scenerio is as follows: - 1 QNX host->Eth->1 SCO host the SCO host is configured with it's IP the QNX host is configured with another IP both in the same domain, ie, 172.20.3.XX... (3 Replies)
Discussion started by: gavon
3 Replies
Login or Register to Ask a Question