Linux_记录ping命令的日志包括时间戳

时间:2023-03-09 08:40:16
Linux_记录ping命令的日志包括时间戳

while true; do ping -c 1 www.baidu.com | awk '{print "["strftime("%F %H:%M:%S")"]:"$0}' |grep from >> ping.log;sleep 1; done &

在ping百度的时候发现ping的次数多了之后百度会拒绝,所以改为ping天气网站

while true; do ping -c 1 www.weather.com.cn | awk '{print "["strftime("%F %H:%M:%S")"]:"$0}' |grep from >> ping.log;sleep 1; done &