#!/bin/bash # 检查192.168.1.1―192.168.1.254 主机是否存活
for ip in 192.168.1.{1..254};
do
if ping -c 1 $ip >/dev/null; then
echo "$ip OK."
else
echo "$ip NO!"
fi
done
#!/bin/bash #检查多个域名是否可以访问
URL="www.baidu.com www.sina.com www.jd.com"
for url in $URL; do
HTTP_CODE=$(curl -o /dev/null -s -w %{http_code} http://$url)
if [ $HTTP_CODE -eq 200 -o $HTTP_CODE -eq 301 ]; then
echo "$url OK."
else
echo "$url NO!"
fi
done
原文链接:https://www.f2er.com/bash/392554.html