Link to home
Start Free TrialLog in
Avatar of rleyba828
rleyba828Flag for Australia

asked on

How to send output of ping to syslog (with timestamp and optional comments)

Hi Team,
  I have a centos 6.6 machine and I am just looking for a quick bash script that can send continuous ping with timestamp to syslog.

This one is working for me:

[root@cloudhost ~]#  ping www.cnn.com -i 5 | perl -nle 'print scalar(localtime), " ", $_' 
Thu Jul  9 05:22:29 2015 PING turner.map.fastly.net (199.27.79.73) 56(84) bytes of data.
Thu Jul  9 05:22:29 2015 64 bytes from 199.27.79.73: icmp_seq=1 ttl=59 time=14.9 ms
Thu Jul  9 05:22:34 2015 64 bytes from 199.27.79.73: icmp_seq=2 ttl=59 time=15.3 ms
Thu Jul  9 05:22:39 2015 64 bytes from 199.27.79.73: icmp_seq=3 ttl=59 time=14.9 ms
^C
[root@cloudhost ~]# 

Open in new window


However,   I can't seem to redirect it to logger so that it logs the entire output to syslog.

Also,  I need to put comments on the output so the one above becomes like this.  I want to include the comments "probe-external-site" in the output.

[root@cloudhost ~]#  ping www.cnn.com -i 5 | perl -nle 'print scalar(localtime), " ", $_' 
Thu Jul  9 05:22:29 2015 probe-external-site PING turner.map.fastly.net (199.27.79.73) 56(84) bytes of data.
Thu Jul  9 05:22:29 2015 probe-external-site 64 bytes from 199.27.79.73: icmp_seq=1 ttl=59 time=14.9 ms
Thu Jul  9 05:22:34 2015 probe-external-site 64 bytes from 199.27.79.73: icmp_seq=2 ttl=59 time=15.3 ms

Open in new window

Thanks for any help.
Avatar of arnold
arnold
Flag of United States of America image

A continuous Ping is a difficulty since it copiously run never ending as is needed if you pass the data to the next command.
A cron with a single ping -c 1 |logger -f facility.level

Will creat an entry every time it runs.the syslog event will be delayed by how long it takes ping to receive a response and pass the output to logger.
Avatar of rleyba828

ASKER

Hi Arnold....unfortunately, the cron job only runs at most, once per minute and our continuous pings need to be much more granular than that.

What I am looking for is something along the lines of:

 ping www.cnn.com -i 5 | perl -nle 'print scalar(localtime), " ", $_' |logger -f facility.level

Open in new window


Thanks.
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial