{"id":2340,"date":"2016-01-29T10:12:49","date_gmt":"2016-01-29T18:12:49","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=2340"},"modified":"2017-02-14T14:41:22","modified_gmt":"2017-02-14T22:41:22","slug":"is-the-server-alive","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=2340","title":{"rendered":"Is the server alive?"},"content":{"rendered":"<p>I\u2019ve been working on a server that has been going offline. I can tell it\u2019s offline because I get an indicator in my mail program that shows that I can\u2019t get mail. The first time it happened we called over to the data center and had them restart everything. That worked for a while but then it happened again. This time we went over to the data center and the server itself was fine. Replacing the switch that connected two servers made the problem go away. A few weeks later, the server went offline again. This time it looked like it was a DDOS. It has been fine ever since, but we wanted to have a better way of knowing that there is an issue than me happening to look at my email program and noticing that I wasn\u2019t getting mail.<\/p>\n<p>One way to see if it is alive is to ping the server every few minutes. If I get no response, then send a text to the owner and an email to me. <\/p>\n<p>I have a couple of cron job on my server running under my crontab that send out notifications by text or email every minute. So I edited the crontab to add another job to its list.<\/p>\n<p>To see the cron jobs, <i>crontab -l -u myuserid<\/i>. To edit type, <i>crontab -e<\/i>.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n# m h&nbsp;&nbsp;dom mon dow&nbsp;&nbsp; command\n*\/1 * * * * \/home\/myuserid\/reminder.sh\n*\/1 * * * * \/home\/myuserid\/ping_remote_server.sh<\/code><\/pre><\/p>\n<p>Here\u2019s the shell script I wrote to ping the server and send out notifications.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n#!\/bin\/sh\nping -c 1&nbsp;&nbsp;-q remoteservername.com&nbsp;&nbsp;1&gt;\/dev\/null 2&gt;&amp;1;\nreturn_code=$?;\n\nif [ $return_code -ne 0 ]; then\n&nbsp;&nbsp;&nbsp;&nbsp;#echo &quot;Failure&quot;;\n&nbsp;&nbsp;&nbsp;&nbsp;mail -s &quot;Server Down&quot;&nbsp;&nbsp;8055551212@mobile.mycingular.com myuserid@MyServer.com &lt; \/dev\/null\nfi\n<\/code><\/pre><\/p>\n<p>I ping it once (-c 1), quietly\u2014since I don\u2019t care about the result (-q) and send the result and any error messages to \/dev\/null. All I care about is whether it was successful. Every Linux command has an exit status code. You can access it with $?. I only care if the command ran successfully, so I check to see if it is not 0.<\/p>\n<p>I don\u2019t need any details in the text that I send, so I set the subject and grab the content from <\/dev\/null.\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve been working on a server that has been going offline. I can tell it\u2019s offline because I get an indicator in my mail program that shows that I can\u2019t get mail. The first time it happened we called over to the data center and had them restart everything. That worked for a while but &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=2340\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Is the server alive?<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2340","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2340"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2340\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}