I run a Ubuntu 12.04 apache web server from home as a hobby. My internet connection is flaky and sites often go offline. The server keeps running but is disconnected from the internet. Is there a way to find the amount of time server remained disconnected from the internet?

I'm looking for something that runs locally on the server (like a script) rather than a monitoring service that constantly pings my server to check status.


I would use a simple script,


  TEMP=$(wget -O - -o /dev/null | cut -d" " -f6 | sed 's/<\/body><\/html>//')

  echo $TEMP >> /home/my_name/bin/ip_log 
  TODAY=$(date +"%c")
  echo $TODAY >> /hme/my_name/bin/ip_log

  exit 0 is checkip.dyndns.org, by the way. Call the script my_check, make it executable (chmod 755 my_check), and have it run with crontab every minute:

*/1 * * * * /home/my_name/bin/my_check

or whenever you like. Cheap, simple, customizable, no ping.


For free and simple, try a service like pingdom which (assuming your website is available globally) will allow you to load a HTTP or HTTPS page on a schedule and report on when it's unavailable and for how long. Other services are available but I've found Pingdom good for monitoring a single page to confirm this sort of thing.

  • My ISP blocks ping requests. Also I'm not looking to check the current status of the server, rather I want to see the time spent offline. There must be connection/disconnection info in logs. I was looking for a script that could parse them and give me a report of time spent offline. – koogee Feb 10 '14 at 13:50
  • The name is misleading - the default Pingdom check is a HTTP request. It then logs the results to show statistics which include "downtime" - i.e. time your server was inaccessible. Really there's two ways of looking at it - do you want to know when your server was inaccessible via the internet, or when you server could not access the internet? Different questions. The second would presumably be some kind of ping-the-internet-and-parse-the-response type script. – ArgumentBargument Feb 10 '14 at 13:53
  • I was thinking more along the lines of parsing /var/log/syslog for eth0 state. – koogee Feb 10 '14 at 14:01
  • 1
    eth0 state will likely have nothing to do with your internet connection, because it's most likely connected to a switch or your router. Unless that's the device that is flakey, monitoring that will show you that you're always connected. – mfinni Feb 10 '14 at 14:04
  • Thats true. Maybe something along the lines of your suggestion then. Something that pings the internet and checks response. how about a wget script that checks checkip.dyndns.org? – koogee Feb 10 '14 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.