I have a continuous ping running with export/timestamp to a file. It ran for about 10 hours and the last line in my output is:
ping: sendmsg: Network is unreachable
It looks like the ping stopped after that occurred. Should it do that? Is there a way to make that not happen?
I'm running the ping via a simple loop on the command line. I think ping just broke out and stopped, but I figured I would show how I'm running this.
Anyone know what I can do to make ping continue after a failure like that? By default it should just keep going
nohup ping -i 10 <SERVERNAME> | while read line; do echo "$(date): $line" ; done >> pinglog_.log &
I've never had ping die on me like that, no. (Though you have not said what your system is -- it's possible you have a different implementation of ping than I do.) I think it's more likely it died (or perhaps froze) because you closed whatever terminal it was attached to... Putting it in background does not stop that, you need to redirect stdin/stdout/stderr.
YYYY-MM-DD HH:MM:SS dates are best for log files because they compare alphabetically. You can look for lines alphabetically greater than "2014-06-27 01:00:00" and that will do exactly what you'd think it should do.
You can avoid running date 10,000 times for 10,000 lines by feeding it into awk once and only once. Use nawk on solaris.
You should add 'disown' after & if your shell is bash or ksh. Most other shells don't need it.
( nohup ping -i 10 <SERVERNAME> | awk '{ print strftime("%Y-%m-%d %H:%M:%S", systime()), $0 }' >> pinglog_.log & disown ) >/dev/null 2>/dev/null </dev/null
Thanks. I'm actually on Linux (Redhat E6.3)
Closing the terminal didnt do it as I had logged back in and ran a tail before it had stopped. I was just surprised that the ping did that as its normally continuous by default.
Thanks for the awk tip, I suppose that would be more efficient, but for this case I'm just doing something for troubleshooting. I have done it like that though, thanks.