bash以自动输入文件每日 ping测试



我每天正在为100 IP的PING测试,每天输入文件IP会更新,因为它的动态。我将输入(100 IP列表(指定为第一个参数。因为以下脚本将每10分钟运行一次

注意: - 我每天都在使用不同的IP,因此需要每天更改输入文件

在4月1日上午12点运行脚本作为背景

sh ping.sh IPlist_apr1.txt & 

在第二天我的次要脚本(将创建更新的IP(将在此文件格式中选择其他IP集合'iplist_apr2.txt'在第三天-Iplist_apr3.txt ...它将每天在CWD上记录$ 1.LOG。

同样,此过程仍在继续,我实际上正在寻找的ping脚本应该每天处理列表作为第一个参数。

我实际脚本的片段。

t=10m                         
ip=$1                     #### specify the file having IP's
while sleep $t
do
    if ping -c1 $ip >/dev/null 2>&1; then
        echo "`date +%H:%M`: $ip is up";
    else
        echo "`date +%H:%M`: $ip is down"; 
    fi >>$1.log;
done

您需要 read 来自参数名称的文件。

  while IFS= read -r ipaddr; do
    if ping -c1 "$ipaddr"; then
      status=up
    else
      status=down
    fi
    printf '%s: %s is %sn' "$(date +%H:%M)" "$ipaddr" "$status"
  done < "$1"

请注意,这将运行一批ping,然后退出。呼叫者应负责睡觉10分钟并为输入指定正确的文件名。

最新更新