首先是長時間ping,這個很是簡單,使用參數-c便可:
[root@test ~]# ping 192.168.2.1 -c 10 ide
上面咱們ping了10次,每次的時間1秒,所以好比你要ping連天那麼就是60*60*24*2=172800。
接下來是加時間戳:
root@test ~]# ping 192.168.2.1 -c 10 | awk '{ print $0"\t" strftime("%H:%M:%S",systime()) } '
PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data. 10:30:21
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.436 ms 10:30:21
64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=0.343 ms 10:30:22spa
而後咱們把信息輸出到文本:
[root@test ~]# ping 192.168.2.1 -c 10 | awk '{ print $0"\t" strftime("%H:%M:%S",systime()) } '>ping.log
[root@test ~]# cat ping.log
PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data. 10:37:23
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.398 ms 10:37:23
64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=0.288 ms 10:37:24orm
最後,咱們須要把任務放到後臺去:
[root@test ~]# nohup ping 192.168.2.1 -c 10 | awk '{ print $0"\t" strftime("%H:%M:%S",systime()) } '>ping1.log &
[1] 2616
[root@test ~]# ls
anaconda-ks.cfg check1.sh Desktop eygle.com httpd login pass.conf ping1.log ping.log test1.sh test1.sh1
[root@test ~]# cat ping1.log
PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data. 10:40:22
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.373 ms 10:40:22it
注:nohup ping 192.168.2.1 -c 10 | awk '{ print $0"\t" strftime("%Y-%m-%d %H:%M:%S",systime()) } '>ping1.log 2>&1 &class
這樣每隔4K左右會打印到文件test