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.
rleyba828Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arnoldCommented:
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.
0
rleyba828Author Commented:
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.
0
arnoldCommented:
Run  a script such as
while true; do
ping www.cnn.com -c 1 |logger -p local6.info
sleep 4
done

Open in new window


Syslog will pretend the time the event was received, no need to do that
Check the flag you need to identify the facility and priority
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.