【发布时间】:2014-07-16 23:30:26
【问题描述】:
我正在从一个 txt 文件中读取数百个 IP 地址,想将列表 ping 到文件末尾。希望它在循环中运行,读取到文件末尾,然后再次从第一个地址开始。
trap 'echo ****Interrupted****; exit'INT
echo -n "Enter the file name with the ip addresses"
read file
echo -n "Enter the file name for the log file"
read log
while read line
do
echo "pinging: "$line
echo -e "">>$log
echo -n "NEXT PING: ">>$log
echo -n "$line" : " >>$log
$ping -c 3 -W 2 $line >>$log
done <"$file"
【问题讨论】:
-
用
true条件将你的while循环包裹在另一个while循环中。也许while true ; do while read line ; do ...... done < "$file" ; sleep 5 #?; done祝你好运。