Sponsored Content
Top Forums Shell Programming and Scripting Ping Host Until it is up and email Post 302702703 by Corona688 on Tuesday 18th of September 2012 05:22:17 PM
Old 09-18-2012
I think you have the loop in the wrong place. You don't want to ping ALL the hosts before you email, do you?

You also don't want to call your function the same thing as an external command, that could infinite-loop or worse.

I don't think you need a function here anyway.

This will work with linux ping but not other pings, which don't all return a value properly.

Code:
for H in $HOSTS
do
        while ! ping -c 1 $H > /dev/null 2> /dev/null
        do
                true
        done

        echo "$H is up"
done

This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

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

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

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

4. UNIX for Advanced & Expert Users

Unable to send eMail from a UNIX-Host ( using mailx ) to a Outlook-email-addres(Win)

Hi A) I am able to send eMail using mailx from a UNIX ( solaris 8 ) host to my Outlook-email-ID : FName.Surname@Citigroup.com ( This is NOT my actual -eMail-ID). But in Outlook the "From :" eMail address is displayed as " usr1@unix-host1.unregistered.email.citicorp.com " .i.e the words... (2 Replies)
Discussion started by: Vetrivela
2 Replies

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

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

unable to ping a host in another domain

Hello I have a server in it.siroe.com I added it.siroe.com in /etc/resolv.conf. I still can't ping the server. any service to restart here? any other file to edit? thx (4 Replies)
Discussion started by: melanie_pfefer
4 Replies

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

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

10. AIX

Ping to remote host failed

Actually. I was getting a ping to remote host failed for one of my etherchannel. When I checked it was in backup adapter and again I use to faileover and brought to primary channel. But it was again going to backup channel and giving me the alert ping to remotehost failed. When I checked the load... (3 Replies)
Discussion started by: Mohamed Thamim
3 Replies
CPAN::Mirrors(3pm)					 Perl Programmers Reference Guide					CPAN::Mirrors(3pm)

NAME
CPAN::Mirrors - Get CPAN miror information and select a fast one SYNOPSIS
use CPAN::Mirrors; my $mirrors = CPAN::Mirrors->new; $mirrors->parse_from_file( $mirrored_by_file ); my $seen = {}; my $best_continent = $mirrors->find_best_continents( { seen => $seen } ); my @mirrors = $mirrors->get_mirrors_by_continents( $best_continent ); my $callback = sub { my( $m ) = @_; printf "%s = %s ", $m->hostname, $m->rtt }; $mirrors->get_mirrors_timings( @mirrors, $seen, $callback ); @mirrors = sort { $a->rtt <=> $b->rtt } @mirrors; print "Best mirrors are ", map( { $_->rtt } @mirrors[0..3] ), " "; DESCRIPTION
new( LOCAL_FILE_NAME ) continents() Return a list of continents based on those defined in MIRRORED.BY. countries( [CONTINENTS] ) Return a list of countries based on those defined in MIRRORED.BY. It only returns countries for the continents you specify (as defined in "continents"). If you don't specify any continents, it returns all of the countries listed in MIRRORED.BY. mirrors( [COUNTRIES] ) Return a list of mirrors based on those defined in MIRRORED.BY. It only returns mirrors for the countries you specify (as defined in "countries"). If you don't specify any countries, it returns all of the mirrors listed in MIRRORED.BY. get_mirrors_by_countries( [COUNTRIES] ) A more sensible synonym for mirrors. get_mirrors_by_continents( [CONTINENTS] ) Return a list of mirrors for all of continents you specify. If you don't specify any continents, it returns all of the mirrors. get_countries_by_continents( [CONTINENTS] ) A more sensible synonym for countries. best_mirrors "best_mirrors" checks for the best mirrors based on the list of continents you pass, or, without that, all continents, as defined by "CPAN::Mirrored::By". It pings each mirror, up to the value of "how_many". In list context, it returns up to "how_many" mirror. In scalar context, it returns the single best mirror. Arguments how_many - the number of mirrors to return. Default: 1 callback - a callback for find_best_continents verbose - true or false on all the whining and moaning. Default: false continents - an array ref of the continents to check If you don't specify the continents, "best_mirrors" calls "find_best_continents" to get the list of continents to check. get_n_random_mirrors_by_continents( N, [CONTINENTS] Returns up to N random mirrors for the specified continents. Specify the continents as an array reference. get_mirrors_timings( MIRROR_LIST, SEEN, CALLBACK ); Pings the listed mirrors and returns a list of mirrors sorted in ascending ping times. find_best_continents( HASH_REF ); "find_best_continents" goes through each continent and pings "N" random mirrors on that continent. It then orders the continents by ascending median ping time. In list context, it returns the ordered list of continent. In scalar context, it returns the same list as an anonymous array. Arguments: n - the number of hosts to ping for each continent. Default: 3 seen - a hashref of cached hostname ping times verbose - true or false for noisy or quiet. Default: false callback - a subroutine to run after each ping. ping_cache_limit - how long, in seconds, to reuse previous ping times. Default: 1 day The "seen" hash has hostnames as keys and anonymous arrays as values. The anonymous array is a triplet of a "CPAN::Mirrored::By" object, a ping time, and the epoch time for the measurement. The callback subroutine gets the "CPAN::Mirrored::By" object, the ping time, and measurement time (the same things in the "seen" hashref) as arguments. "find_best_continents" doesn't care what the callback does and ignores the return value. AUTHOR
Andreas Koenig "<andk@cpan.org>", David Golden "<dagolden@cpan.org>", brian d foy "<bdfoy@cpan.org>" LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See <http://www.perl.com/perl/misc/Artistic.html> perl v5.18.2 2014-01-06 CPAN::Mirrors(3pm)
All times are GMT -4. The time now is 12:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy