Here is my code:
def ping_host(self, hostname, ping_cmd='/usr/bin/ping', count=1, timeout=400):
cmd = [ping_cmd, '-c%s' % count, '-W%s' % timeout, hostname]
(output, error) = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True).communicate()
print ' '.join( cmd )
print output, error
When I run it I get this output:
/usr/bin/ping -c1 -W400 tools-dev1.example.com
Usage: ping [-aAbBdDfhLnOqrRUvV64] [-c count] [-i interval] [-I interface]
[-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
[-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
[-w deadline] [-W timeout] [hop1 ...] destination
Usage: ping -6 [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
[-l preload] [-m mark] [-M pmtudisc_option]
[-N nodeinfo_option] [-p pattern] [-Q tclass] [-s packetsize]
[-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline]
[-W timeout] destination
I assume I am doing something wrong with the first argument, cmd
, I am passing to Popen()
, but I don't know what. If I cut-n-paste /usr/bin/ping -c1 -W400 tools-dev1.example.com
to a command line it works fine.