{"id":351,"date":"2009-06-16T14:24:55","date_gmt":"2009-06-16T14:24:55","guid":{"rendered":"http:\/\/davstott.me.uk\/?p=351"},"modified":"2013-01-15T18:53:49","modified_gmt":"2013-01-15T18:53:49","slug":"icmp-ping-connection-monitor-script","status":"publish","type":"post","link":"https:\/\/davstott.me.uk\/index.php\/2009\/06\/16\/icmp-ping-connection-monitor-script\/","title":{"rendered":"icmp ping connection monitor script"},"content":{"rendered":"<p>This was one of those tasks that was quicker to write my own than it was to Google up one of the several hundred other identical monitoring scripts. <\/p>\n<p>This script monitors whether or not a host is responding to ICMP and can be happily set to a resolution of 1 second. It&#8217;s written in bash and will happily run on my linux. It should run on yours, too.<\/p>\n<p><!--more--><\/p>\n<p><code><br \/>\n  .\/pingit 1 myHostname.dyndns.org &gt; \/var\/log\/myIspIsNotIdeal.log<br \/>\n<\/code><\/p>\n<p><code><\/p>\n<pre>\r\n#!\/bin\/sh\r\nif [ $# -ne 2 ]\r\n  then\r\n  echo \"Usage: $0 &lt;timeout in seconds&gt; &lt;hostname to ping&gt;\"\r\n  exit 1\r\nfi\r\nwhile true\r\ndo\r\n  echo -n \"$(date) \"\r\n  ping -q -c 1 -W $1 $2 &gt; \/dev\/null\r\n  case $? in\r\n  1)\r\n    echo \"down\"\r\n    ;;\r\n  0)\r\n    echo \"ok\"\r\n    sleep $1\r\n    ;;\r\n  2)\r\n    echo \"the damage report machine has exploded\"\r\n    ;;\r\n  esac\r\ndone\r\n<\/pre>\n<p><\/code><\/p>\n<p>Run it and redirect its output to a file for later grepping. Once I&#8217;m happy its bedded in and working, and I&#8217;ve finished tarting it about a bit, I&#8217;ll make it only output a line on failure.<\/p>\n<p>If you&#8217;d prefer your monitoring to be slightly more capable than this, and also draw pretty rrdtool graphs of the results, then I recommend you check out <a href=\"http:\/\/oss.oetiker.ch\/smokeping\/\">Smokeping<\/a>, which is in the Debian repositories and is very simple to set up.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This was one of those tasks that was quicker to write my own than it was to Google up one of the several hundred other identical monitoring scripts. This script monitors whether or not a host is responding to ICMP and can be happily set to a resolution of 1 second. It&#8217;s written in bash [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-351","post","type-post","status-publish","format-standard","hentry","category-general"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/davstott.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davstott.me.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davstott.me.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davstott.me.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davstott.me.uk\/index.php\/wp-json\/wp\/v2\/comments?post=351"}],"version-history":[{"count":8,"href":"https:\/\/davstott.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/351\/revisions"}],"predecessor-version":[{"id":1511,"href":"https:\/\/davstott.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/351\/revisions\/1511"}],"wp:attachment":[{"href":"https:\/\/davstott.me.uk\/index.php\/wp-json\/wp\/v2\/media?parent=351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davstott.me.uk\/index.php\/wp-json\/wp\/v2\/categories?post=351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davstott.me.uk\/index.php\/wp-json\/wp\/v2\/tags?post=351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}