shell检查主机是否alive
if ping -c 1 -W 1 "$hostname_or_ip_address"; then
echo "$hostname_or_ip_address is alive"
else
echo "$hostname_or_ip_address is pining for the fjords"
fi#!/bin/bash
ping -q -w1 -c1 google.com &>/dev/null && echo online || echo offline#!/bin/bash
ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && echo ok || echo error#!/bin/bash
wget -q --spider http://google.com
if [ $? -eq 0 ]; then
echo "Online"
else
echo "Offline"
fi参考
Last updated