1827293 Members
3146 Online
109717 Solutions
New Discussion

Re: ping + date

 
SOLVED
Go to solution
Dushyant.Tyagi
Occasional Advisor

ping + date

Hi Gurus !!!
is it possibe in linux to take the continues ping output in below format

ping + date
64 bytes from 192.168.x.x: icmp_seq=5 ttl=255 time=0.229 ms Thu Nov 9 18:15:04 IST 2006

3 REPLIES 3
Silju
Advisor

Re: ping + date

Hi,

ping does not have option to show the date. You can use a script instead of it.

while [ 1 ]; do ping -c 1 "hostname or IP"; date; sleep 1;done

:)

Warm Regards
Silju
Technology to empower all
Ivan Ferreira
Honored Contributor
Solution

Re: ping + date

Use the following perl code, create a file called tstamp.pl:

open(LOGFILE,">&STDOUT") ;

if ( $ARGV[0] ) {

close(LOGFILE) ;
open(LOGFILE,">> $ARGV[0]") or die "Cannot open file $ARGV[0]\n" ;
select(LOGFILE) ; # If commented out, nothing
$| = 1 ; # is printed to $ARGV[0] later on

}

while ( ) {

( $sec, $min, $hour, $day, $month, $year ) = localtime() ;
$month += 1 ;
$year += 1900 ;

printf LOGFILE ("%02d.%02d.%04d %02d:%02d:%02d: %s", $day, $month,
$year,
$hour, $min, $sec, $_) ;

}


For example:

ping localhost | tstamp.pl

09.11.2006 10:57:21: PING localhost (127.0.0.1): 56 data bytes
09.11.2006 10:57:21: 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=1 ms
09.11.2006 10:57:22: 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0 ms

Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Dushyant.Tyagi
Occasional Advisor

Re: ping + date

Silju Ivan Ferreira

Thanx a lot for ur quick Support ,

Ivan, this is what i want !! . Thank u