Ping Monitor


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ping Monitor
# 1  
Old 03-13-2013
Ping Monitor

Hello,

I need a simple shell script. If you can help I'd appreciate it. I'm sorry for my English.

I want to send ping to 3 web site
Code:
I want to send 5 ping to 3 web site

result:

1- www.google.com UP
2- www.yahoo.com UP
3- www.myserver.com DOWN

If myserver.com is down I want to 10 ping all of them again (To avoid errors resulting)

result:

1- www.google.com UP
2- www.yahoo.com UP
3- www.myserver.com DOWN

I want to run a curl command.


If first ping result is:

1- www.google.com DOWN
2- www.yahoo.com UP
3- www.myserver.com DOWN

I don't want to run a curl command.

# 2  
Old 03-14-2013
How about this:

Code:
#!/bin/bash
function checksites {
    SEND=$1
    shift
    while [ $# -gt 0 ]
    do
        ping -n $SEND $1 2>&1 | grep -q "[ (]0%"
        if [ $? -eq 0 ]
        then
            printf " UP"
        else
            printf " DOWN"
        fi
        shift
    done
}
CHECK=( www.google.com www.yahoo.com www.myserver.com )
RESULT=( $(checksites 5 ${CHECK[@]}) )

[ "${RESULT[2]}" = "DOWN" ] && RESULT=( $(checksites 10 ${CHECK[@]}) )

if [ "${RESULT[*]}" = "DOWN UP DOWN" ]
then
    echo "Run your curl command here"
fi

# 3  
Old 03-14-2013
Thank you very much. I've tried a non-working ip number on server 3.
I did't get any results when I run.
# 4  
Old 03-14-2013
Both server1 and server3 need to be non working (DOWN UP DOWN) to get a result, isn't that what you wanted?

For just server3 you will need:

Code:
if [ "${RESULT[*]}" = "UP UP DOWN" ]
then     
    echo "Run your OTHER curl command here"
fi

# 5  
Old 03-14-2013
Hello,

I tried it. but any curl command does not work
# 6  
Old 03-14-2013
please post your updated script, between [code] and [/code] tags and any output or error messages you are getting.
# 7  
Old 03-14-2013
I am not receiving any output.

Code:
#!/bin/bash
function checksites {
    SEND=$1
    shift
    while [ $# -gt 0 ]
    do
        ping -n $SEND $1 2>&1 | grep -q "[ (]0%"
        if [ $? -eq 0 ]
        then
            printf " UP"
        else
            printf " DOWN"
        fi
        shift
    done
}
CHECK=( www.google.com www.yahoo.com www.ZB37NNRHHS4Fmyserver.com )
RESULT=( $(checksites 5 ${CHECK[@]}) )

[ "${RESULT[2]}" = "DOWN" ] && RESULT=( $(checksites 10 ${CHECK[@]}) )

if [ "${RESULT[*]}" = "UP UP DOWN" ]
then     
    curl -o /root/100mb.test "http://cachefly.cachefly.net/100mb.test"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Infrastructure Monitoring

Searching for Saas Monitor service which monitor my servers which are sitting in different providers

Sorry if this is the wrong forum Searching for Saas Monitor service which monitor my servers which are sitting in different providers . This monitor tool will take as less CPU as possible , and will send info about the server to main Dashboard. The info I need is CPU / RAM / my servers status (... (1 Reply)
Discussion started by: umen
1 Replies

2. 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

3. Shell Programming and Scripting

How to get reason for ping failure using perls Net::Ping->new("icmp");?

Hi I am using perl to ping a list of nodes - with script below : $p = Net::Ping->new("icmp"); if ($p->ping($host,1)){ print "$host is alive.\n"; } else { print "$host is unreacheable.\n"; } $p->close();... (4 Replies)
Discussion started by: tavanagh
4 Replies

4. Hardware

Fedora 16 dual monitor - dual head - automatic monitor shutdown

Hi, I am experiencing troubles with dual monitors in fedora 16. During boot time both monitors are working, but when system starts one monitor automatically shut down. It happend out of the blue. Some time before when I updated system this happend but then I booted older kernel release and... (0 Replies)
Discussion started by: wakatana
0 Replies

5. IP Networking

PING

I am unable to ping my remote server.My server is unable to ping the same. both are able to ping the gateway. both the ip's are on same network.i use a proxy tunnel on my remote server.Help if any clues. (6 Replies)
Discussion started by: oslbhavana
6 Replies

6. 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

7. Shell Programming and Scripting

Monitor: Read from the monitor

Hello, I would like to write a script that use the display as an input. In the display there is a list of file. I want to use it as an array and this would be the input in my script. Does somebody know how do I make it? (2 Replies)
Discussion started by: mig8
2 Replies

8. Linux

Not able to ping

Hi All, Need your help one more time. I am trying to ping a linux machine which is not responding to ping. However traceroute can reach the machine and I can log in to it by ssh. I have checked /proc/sys/net/ipv4/icmp_echo_ignore_all it is already set as "0". It is not happening in the... (1 Reply)
Discussion started by: ailnilanjan
1 Replies

9. IP Networking

ping monitor required

Hi all, Anyone know of freeware or shareware app/demon that will ping and address at regular intervals and keep a log of the response times and preferasbly graph the results. I am using solaris 8 on a sparc. I need it to trace some intermittant connectivity problems. Cheers Mike (1 Reply)
Discussion started by: mscomms
1 Replies
Login or Register to Ask a Question