rleyba828
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:
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.
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 ~]#
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
Thanks for any help.
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:
Thanks.
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
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.