0 总结
Get to the points first. The article comes from LawsonAbs!
- updata on 20200505:修改相关格式
1. 原理
使用shell
脚本批量执行ping
命令。
2.主要步骤
- 1)变量
destination_ip
是目标主机的ip地址。 - 2)
ping
后的-c1
参数代表的是本主机向目标主机发送的最多测试包数。 - 3)
&>
为重定向 - 4)新建一个文件,
vi pingtest.sh
,添加以下代码1/2/3:
#!/bin/bash
destination_ip=192.168.109.2
if ping -c1 $destination_ip &>/dev/null
then
echo "$destinaion_ip is online."
else
echo "$destination_ip is offline."
fi
2 . 代码2
#!/bin/bash
$destination_ip
read -p "please inpur ip :" destination_ip
if ping -c1 $destination_ip &>/test.txt
then
echo "$destination_ip is online."
else
echo "$destination_ip is offline."
fi
3 . 代码3
#!/bin/bash
if ping -c1 $1 &>/test.txt
then
echo "$1 is online."
else
echo "$1 is offline."
fi