{"id":1366,"date":"2017-04-19T13:14:34","date_gmt":"2017-04-19T13:14:34","guid":{"rendered":"http:\/\/scunster.co.uk\/?p=1366"},"modified":"2017-04-19T13:14:34","modified_gmt":"2017-04-19T13:14:34","slug":"linux-script-to-check-if-ip-address-or-addresses-are-reachable-send-email-notification-if-not","status":"publish","type":"post","link":"https:\/\/scunster.co.uk\/?p=1366","title":{"rendered":"Linux &#8211; script to check if IP address or addresses are reachable &#038; send email notification if not"},"content":{"rendered":"<p>Edit the below script to suit your needs and add it to CRON, run every 15 minutes, every hour or whatever you need.<\/p>\n<p>It will email you if any of your chosen ip addresses are offline<\/p>\n<pre>\r\n#!\/bin\/bash\r\n# ip ping notification script by scunster\r\n# add ip \/ hostnames separated by space\r\nHOSTS=\"192.168.1.1 192.168.1.2 192.168.1.3\"\r\n# no ping request\r\nCOUNT=1\r\n# email report\r\nSUBJECT=\"Ping Failure Notice!\"\r\nEMAILID=\"your@email_address.co.uk\"\r\nfor myHost in $HOSTS;\r\ndo\r\ncount=`ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }'`\r\nif [ $count -eq 0 ]\r\nthen\r\necho \"Host : $myHost is down (ping failed) at $(date)\" | mail -s \"$SUBJECT\" $EMAILID\r\n#else\r\n#echo \"Host : $myHost is up (ping passed) at $(date)\" | mail -s \"$SUBJECT\" $EMAILID\r\nfi\r\ndone\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Edit the below script to suit your needs and add it to CRON, run every 15 minutes, every hour or whatever you need. It will email you if any of your chosen ip addresses are offline #!\/bin\/bash # ip ping notification script by scunster # add ip \/ hostnames separated by space HOSTS=&#8221;192.168.1.1 192.168.1.2 192.168.1.3&#8243; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,12],"tags":[111,115,342,245,346,345,344,343,124,341,105,82],"class_list":["post-1366","post","type-post","status-publish","format-standard","hentry","category-linux","category-webhosting","tag-cron","tag-email","tag-host","tag-ip-address","tag-is-down","tag-is-up","tag-isdown","tag-isup","tag-lan","tag-ping","tag-script","tag-web"],"_links":{"self":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1366"}],"version-history":[{"count":1,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1366\/revisions"}],"predecessor-version":[{"id":1367,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1366\/revisions\/1367"}],"wp:attachment":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}