Do ping cycle test through shell script under Mac OS
Do ping cycle test through shell script
System environment:
Operating system: MAC OS
An interesting and useful system maintenance script that tests the connectivity of network hosts through shell script:
[tiany@localhost ~] $cat ping.sh
#! / bin/bash
For i in `seq 254`
Do
Ip=192.168.1.$i
Ping-C1 $ip > / dev/null 2 > & 1
[$?-eq 0] & & echo "$ip is alive" | | echo "$ip is not alive"
Done
[tiany@localhost ~] $sh ping.sh
192.168.1.1 is alive
192.168.1.2 is not alive
192.168.1.3 is not alive
192.168.1.4 is not alive
192.168.1.5 is not alive
192.168.1.6 is not alive
Transfer to another:
Use shell script to implement all hosts in the ping network segment:
#! / bin/sh
# ping all host
# edit by www.jbxue.com
# find from / etc/hosts for host info,and filter IP address
Cat / etc/hosts | grep-v ^ # | grep-v ^ $| while read LINE
Do
For M in `awk'{print $1}'`
Do
If ping-w 1-c 1$ M | grep "100%" > / dev/null
Then
Echo "$M is down"
Else
Echo "$M is up"
Fi
Done
Done