My overall task is to ping each EC2 server I happen to be connected to.
I am using this command to do that:
netstat -W | grep ec2 | cut -d " " -f 18 | sort -u | cut -d "." -f 1,2,3,4 | xargs -0 -p "ping -c 10"
It outputs the right output, but is not calling xargs
per line:
ping -c 10 ec2-107-20-154-211.compute-1.amazonaws.com
ec2-107-20-169-186.compute-1.amazonaws.com
ec2-13-58-191-91.us-east-2.compute.amazonaws
ec2-18-204-248-223.compute-1.amazonaws.com
ec2-18-207-50-150.compute-1.amazonaws.com
ec2-18-234-32-173.compute-1.amazonaws.com
ec2-34-192-54-86.compute-1.amazonaws.com
ec2-34-195-196-96.compute-1.amazonaws.com
ec2-34-206-216-146.compute-1.amazonaws.com
?...^C
The written explanation of each step is:
- Run netstat with the
-W
flag to get complete FQDNs and not short hostnames grep
for ec2cut
the output to get just the hostname columnsort
unique hostnamescut
the hostname again to drop the portnumber from the end e.g.ec2-1-2-3.amazon.com.80
->ec2-1-2-3.amazon.com
xargs
the output toping
each host ten times
I think I am running into an issue with either the OS X variant of xargs
because piping the same output to wc -l
shows eight lines:
netstat -W | grep ec2 | cut -d " " -f 18 | sort -u | cut -d "." -f 1,2,3,4 | wc -l
8
I am focusing on the xargs aspect here. That is the only part of this task that is not apparently working.