#!/bin/sh
echo "---------------------------------------"
server0="localhost"
server1="172.72.101.46"
server2="172.72.101.47"
server3="172.72.103.221"
server4="172.72.103.222"
server5="172.72.103.223"
server6="172.72.103.224"
server7="172.72.103.225"
server8="172.72.103.246"
server9="172.72.103.227"
server10="172.72.103.228"
pingcmd()
{
prefixt="SERVER $1 PING $2"
ping -w 1 -c 1 $2>/dev/null
ret=$?
if [ $ret -eq 0 ]
then printf "$prefixt OK\n"
else printf "$prefixt ERROR\n"
fi
echo "---------------------------------------"
server0="localhost"
server1="172.72.101.46"
server2="172.72.101.47"
server3="172.72.103.221"
server4="172.72.103.222"
server5="172.72.103.223"
server6="172.72.103.224"
server7="172.72.103.225"
server8="172.72.103.246"
server9="172.72.103.227"
server10="172.72.103.228"
pingcmd()
{
prefixt="SERVER $1 PING $2"
ping -w 1 -c 1 $2>/dev/null
ret=$?
if [ $ret -eq 0 ]
then printf "$prefixt OK\n"
else printf "$prefixt ERROR\n"
fi
本文介绍了一个用于批量Ping多个服务器的Shell脚本示例。该脚本定义了一系列服务器地址,并通过自定义函数pingcmd实现对每个服务器的Ping操作。根据Ping结果输出OK或ERROR状态,便于快速检查网络连通性。
549

被折叠的 条评论
为什么被折叠?



