Get the App
SLTechnology News&Howtos  ›  Servers  › 

Do ping cycle test through shell script under Mac OS

Shulou Source: shulou.com Published: 2022-06-02 22:11:33 09月22日 Update

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

Tags: System test host script loop operating system interesting useful test system environment network segment network Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Microsoft OPPO Reno Shulou Tech Info Docker