我写了以下内容
if ping -q -w 1 -c 1 https://www.example.com > /dev/null
then
echo "Internet is up"
else
echo "Internet is down"
此外,如果您能建议我一种使用curl/grep 执行相同操作的方法,那就太好了
使用
nc
实用程序,类似
# After hostname, the port can be specified
# Let's set connection timeout to 1 sec
if nc -zw1 $hostname >/dev/null 2>&1
then
echo "'$hostname' is reachable!"
fi