This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ time for ip in $(< /tmp/pinglist); do ping -c 2 $ip; echo; done | |
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data. | |
64 bytes from 127.0.0.1: icmp_req=1 ttl=64 time=0.115 ms | |
64 bytes from 127.0.0.1: icmp_req=2 ttl=64 time=0.031 ms | |
--- 127.0.0.1 ping statistics --- | |
2 packets transmitted, 2 received, 0% packet loss, time 999ms | |
rtt min/avg/max/mdev = 0.031/0.073/0.115/0.042 ms | |
PING 127.0.0.2 (127.0.0.2) 56(84) bytes of data. | |
64 bytes from 127.0.0.2: icmp_req=1 ttl=64 time=0.089 ms | |
64 bytes from 127.0.0.2: icmp_req=2 ttl=64 time=0.033 ms | |
--- 127.0.0.2 ping statistics --- | |
2 packets transmitted, 2 received, 0% packet loss, time 999ms | |
rtt min/avg/max/mdev = 0.033/0.061/0.089/0.028 ms | |
PING 192.168.122.1 (192.168.122.1) 56(84) bytes of data. | |
64 bytes from 192.168.122.1: icmp_req=1 ttl=64 time=0.031 ms | |
64 bytes from 192.168.122.1: icmp_req=2 ttl=64 time=0.077 ms | |
--- 192.168.122.1 ping statistics --- | |
2 packets transmitted, 2 received, 0% packet loss, time 1001ms | |
rtt min/avg/max/mdev = 0.031/0.054/0.077/0.023 ms | |
PING 192.168.100.1 (192.168.100.1) 56(84) bytes of data. | |
64 bytes from 192.168.100.1: icmp_req=1 ttl=64 time=0.076 ms | |
64 bytes from 192.168.100.1: icmp_req=2 ttl=64 time=0.075 ms | |
--- 192.168.100.1 ping statistics --- | |
2 packets transmitted, 2 received, 0% packet loss, time 999ms | |
rtt min/avg/max/mdev = 0.075/0.075/0.076/0.008 ms | |
PING 192.168.127.120 (192.168.127.120) 56(84) bytes of data. | |
64 bytes from 192.168.127.120: icmp_req=1 ttl=64 time=0.028 ms | |
64 bytes from 192.168.127.120: icmp_req=2 ttl=64 time=0.076 ms | |
--- 192.168.127.120 ping statistics --- | |
2 packets transmitted, 2 received, 0% packet loss, time 999ms | |
rtt min/avg/max/mdev = 0.028/0.052/0.076/0.024 ms | |
PING 10.10.10.50 (10.10.10.50) 56(84) bytes of data. | |
From 41.223.35.4 icmp_seq=1 Time to live exceeded | |
From 41.223.35.4 icmp_seq=2 Time to live exceeded | |
--- 10.10.10.50 ping statistics --- | |
2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1001ms | |
real 0m6.067s | |
user 0m0.004s | |
sys 0m0.004s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ time cat /tmp/pinglist | xargs --max-args=1 --max-procs=10 -IZ ping -c 1 Z | |
PING 127.0.0.2 (127.0.0.2) 56(84) bytes of data. | |
PING 192.168.127.120 (192.168.127.120) 56(84) bytes of data. | |
PING 192.168.122.1 (192.168.122.1) 56(84) bytes of data. | |
PING 10.10.10.50 (10.10.10.50) 56(84) bytes of data. | |
64 bytes from 192.168.127.120: icmp_req=1 ttl=64 time=0.043 ms | |
--- 192.168.127.120 ping statistics --- | |
64 bytes from 192.168.122.1: icmp_req=1 ttl=64 time=0.034 ms | |
64 bytes from 127.0.0.2: icmp_req=1 ttl=64 time=0.043 ms | |
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data. | |
--- 192.168.122.1 ping statistics --- | |
1 packets transmitted, 1 received, 0% packet loss, time 0ms | |
rtt min/avg/max/mdev = 0.034/0.034/0.034/0.000 ms | |
PING 192.168.100.1 (192.168.100.1) 56(84) bytes of data. | |
1 packets transmitted, 1 received, 0% packet loss, time 0ms | |
--- 127.0.0.2 ping statistics --- | |
64 bytes from 192.168.100.1: icmp_req=1 ttl=64 time=0.074 ms | |
rtt min/avg/max/mdev = 0.043/0.043/0.043/0.000 ms | |
1 packets transmitted, 1 received, 0% packet loss, time 0ms | |
64 bytes from 127.0.0.1: icmp_req=1 ttl=64 time=0.077 ms | |
--- 127.0.0.1 ping statistics --- | |
1 packets transmitted, 1 received, 0% packet loss, time 0ms | |
rtt min/avg/max/mdev = 0.077/0.077/0.077/0.000 ms | |
rtt min/avg/max/mdev = 0.043/0.043/0.043/0.000 ms | |
--- 192.168.100.1 ping statistics --- | |
1 packets transmitted, 1 received, 0% packet loss, time 0ms | |
rtt min/avg/max/mdev = 0.074/0.074/0.074/0.000 ms | |
From 41.223.35.4 icmp_seq=1 Time to live exceeded | |
--- 10.10.10.50 ping statistics --- | |
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms | |
real 0m0.047s | |
user 0m0.000s | |
sys 0m0.000s |
How do you get around that? Well, locking.. Luckily, the shell has a nifty locking utility that is just perfect for this. Enter flock..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ time cat /tmp/pinglist | xargs --max-args=1 --max-procs=10 -IZ flock -x /tmp/pinglist -c "ping -c 1 Z; echo" | |
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data. | |
64 bytes from 127.0.0.1: icmp_req=1 ttl=64 time=0.096 ms | |
--- 127.0.0.1 ping statistics --- | |
1 packets transmitted, 1 received, 0% packet loss, time 0ms | |
rtt min/avg/max/mdev = 0.096/0.096/0.096/0.000 ms | |
PING 192.168.122.1 (192.168.122.1) 56(84) bytes of data. | |
64 bytes from 192.168.122.1: icmp_req=1 ttl=64 time=0.091 ms | |
--- 192.168.122.1 ping statistics --- | |
1 packets transmitted, 1 received, 0% packet loss, time 0ms | |
rtt min/avg/max/mdev = 0.091/0.091/0.091/0.000 ms | |
PING 192.168.127.120 (192.168.127.120) 56(84) bytes of data. | |
64 bytes from 192.168.127.120: icmp_req=1 ttl=64 time=0.105 ms | |
--- 192.168.127.120 ping statistics --- | |
1 packets transmitted, 1 received, 0% packet loss, time 0ms | |
rtt min/avg/max/mdev = 0.105/0.105/0.105/0.000 ms | |
PING 127.0.0.2 (127.0.0.2) 56(84) bytes of data. | |
64 bytes from 127.0.0.2: icmp_req=1 ttl=64 time=0.126 ms | |
--- 127.0.0.2 ping statistics --- | |
1 packets transmitted, 1 received, 0% packet loss, time 0ms | |
rtt min/avg/max/mdev = 0.126/0.126/0.126/0.000 ms | |
PING 192.168.100.1 (192.168.100.1) 56(84) bytes of data. | |
64 bytes from 192.168.100.1: icmp_req=1 ttl=64 time=0.089 ms | |
--- 192.168.100.1 ping statistics --- | |
1 packets transmitted, 1 received, 0% packet loss, time 0ms | |
rtt min/avg/max/mdev = 0.089/0.089/0.089/0.000 ms | |
PING 10.10.10.50 (10.10.10.50) 56(84) bytes of data. | |
From 41.223.35.4 icmp_seq=1 Time to live exceeded | |
--- 10.10.10.50 ping statistics --- | |
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms | |
real 0m0.105s | |
user 0m0.008s | |
sys 0m0.012s |