killertip
如何获得带时间的ping的结果?
有台服务器是断时续,想通过ping方式了解一下断网的规律,发现ping 的结果中没有系统时间,所以无法得知具体是什么时间容易断网,有什么办法可以同时记录系统时间和发包结果吗?
springwind426
[code]
ping 127.0.0.1 | perl -ne 'use POSIX qw(strftime);print strftime("%Y-%m-%d %H:%M:%S", localtime),"/t",$_;'
或者
ping 127.0.0.1 | gawk '{print strftime("%Y-%m-%d %H:%M:%S") "/t" $0}'
[/code]
icewiner
[code]
#!/usr/bin/env bash
while getopts a: options
do
case $options in
a) ping $OPTARG | gawk '{print strftime("%Y-%m-%d %H:%M:%S") "/t" $0}'
esac
done
[/code]
..勉强实现了:oops:
[code]
[test@localhost bin]$ pingt -a 192.168.1.1
2008-05-08 10:42:42 PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
2008-05-08 10:42:42 64 bytes from 192.168.1.1: icmp_seq=0 ttl=64 time=2.65 ms
2008-05-08 10:42:43 64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.380 ms
2008-05-08 10:42:44 64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.867 ms
2008-05-08 10:42:45 64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.373 ms
[/code]
再问..
如何让"-a"成为默认参数以实现直接输入
[code]
[test@localhost bin]$ pingt 192.168.1.1
[/code]
就可以运行?