My static website generator using poole https://www.xythobuz.de
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ultimatenotifier.html 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <html>
  2. <head>
  3. <meta charset="utf-8" />
  4. <title>Ultimate Notifier Script - xythobuz.org</title>
  5. <meta name="description" content="Sending Push Notifications to an iPhone from a Bash Script" />
  6. <meta name="keywords" content="xythobuz" />
  7. <link rel="author" href="/xythobuz@xythobuz.org">
  8. <link rel="shortcut icon" href="/img/favicon.ico">
  9. <script type="text/javascript" src="/js/sh_main.js"></script>
  10. <link type="text/css" rel="stylesheet" href="/css/sh_bright.min.css" />
  11. <link rel="stylesheet" href="/css/style.css" type="text/css" media="screen" />
  12. <link rel="alternate" type="application/rss+xml" title="Blog Feed" href="/rss.xml">
  13. <link rel="stylesheet" href="/css/gh-fork-ribbon.css" />
  14. <link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
  15. <script type='text/javascript'>
  16. /* <![CDATA[ */
  17. (function() {
  18. var s = document.createElement('script');
  19. var t = document.getElementsByTagName('script')[0];
  20. s.type = 'text/javascript';
  21. s.async = true;
  22. s.src = '//api.flattr.com/js/0.6/load.js?mode=auto&uid=xythobuz&category=text';
  23. t.parentNode.insertBefore(s, t);
  24. })();
  25. /* ]]> */
  26. </script>
  27. </head>
  28. <body onload="sh_highlightDocument('/js/sh/', '.min.js');">
  29. <div id="header">
  30. <h1>xythobuz.org</h1>
  31. <h2>Ultimate Notifier Script</h2>
  32. </div>
  33. <div id="lang"><span id="lang">Translation:
  34. <a href='ultimatenotifier.de.html'>de</a> | <a href='ultimatenotifier.html'>en</a>
  35. </span></div>
  36. <div class="colmask leftmenu"><div class="colleft">
  37. <div class="content">
  38. <div id="flattr">
  39. <a class="FlattrButton" href="http://www.xythobuz.org/ultimatenotifier.html" title="Ultimate Notifier Script">Sending Push Notifications to an iPhone from a Bash Script</a>
  40. </div>
  41. <div id="twitter">
  42. <a href="https://twitter.com/share" class="twitter-share-button" data-via="xythobuz" data-dnt="true" data-related="xythobuz" data-count="vertical">Tweet</a><script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
  43. </div>
  44. <div id="reddit">
  45. <script type="text/javascript">reddit_url = "http://www.xythobuz.org/ultimatenotifier.html";</script>
  46. <script type="text/javascript" src="http://www.reddit.com/static/button/button2.js"></script>
  47. </div>
  48. <h1>Ultimate Notifier Script</h1>
  49. <p>The service <a href="http://ultimatenotifier.com">Ultimate Notifier</a> allows you to send Push-Notification to your iPhone easily. Based on this, you can write shell scripts that are executed regularly via cron. This could inform you about a changed public IP. To do this, save this script somewhere:</p>
  50. <pre class="sh_sh">
  51. #!/bin/sh
  52. ipfile=".currentip"
  53. service="ifconfig.me"
  54. user="username"
  55. pass="password"
  56. message="IP:"
  57. ip=`curl -s $service`
  58. touch $ipfile
  59. lastip=`cat $ipfile`
  60. if [ "$ip" != "$lastip" ]; then
  61. echo "New public IP. Sending notification!"
  62. curl -s "https://www.ultimatenotifier.com/items/User/send/${user}/message=${message}%20${ip}/password=${pass}"
  63. fi
  64. cp /dev/null $ipfile
  65. echo $ip > $ipfile
  66. </pre>
  67. <p>It gets the current public IP via <a href="http://ifconfig.me">ifconfig.me</a> and compares it to the IP stored in a file named .currentip. If they differ, a Push-Notification will be sent and the new IP stored.</p>
  68. <p>With the command</p>
  69. <pre>crontab -e</pre>
  70. <blockquote>
  71. <p>You can add a cronfile entry. To execute the script every 30 minutes, use this:</p>
  72. </blockquote>
  73. <pre>*/30 * * * * /Users/anon/bin/ipnotify.sh</pre>
  74. <p>You can find the code on <a href="https://github.com/xythobuz/Snippets/blob/master/ipnotify.sh">GitHub</a>, too!</p>
  75. <p>Of course, you can extend this principle. This script is called every 5 minutes on my server to notify me about eventual problems.</p>
  76. <pre class="sh_sh">
  77. #!/bin/bash
  78. # Checks for Health of Server and sends notifications to iPhone in case of error
  79. # Checks for:
  80. # - HDD Temperature
  81. # - HDD Space
  82. # - CPU Usage
  83. # Sends a notification via UltimateNotifier
  84. # Depends on bash, wget, hddtemp, grep, awk, sed, ps, sort and head.
  85. # ------------------------------
  86. # ------------------------------
  87. # Your UltimateNotifier Password
  88. UNUsername="YourUserName"
  89. UNPassword="YourPassWord"
  90. # Check for free space
  91. hddMountPoint="bay" # greps for this in mounted hdds
  92. maxPercentFull=75 # minimum percentage to send notification
  93. # Check for CPU Usage of processes
  94. maxCpuUsage=750 # Is in tenths of a percent (420 => 42%)
  95. # Checks hdd temperature
  96. # Depends on hddtemp tool
  97. hddDevice="/dev/sda"
  98. maxHddTemp=50
  99. # ------------------------------
  100. # ------------------------------
  101. # Set $message to your Message and then call this...
  102. function sendNotification {
  103. wget "https://www.ultimatenotifier.com/items/User/send/${UNUsername}/message=${message}/password=${UNPassword}" -O /dev/null -q
  104. echo "$message"
  105. }
  106. # ------------------------------
  107. # ------------------------------
  108. # Check for hdd temperature
  109. hddTemp=`/usr/sbin/hddtemp ${hddDevice} | awk '{print $4}' | awk -F '°' '{print $1}'`
  110. if [ $hddTemp -gt $maxHddTemp ]; then
  111. message="Marvin's HDD has reached ${hddTemp}°C!"
  112. sendNotification
  113. fi
  114. # Check for free space on hdd
  115. spaceUsed=`df -h | grep ${hddMountPoint} | awk '{print $5}' | sed 's/%//'`
  116. if [ $spaceUsed -gt $maxPercentFull ]; then
  117. message="Marvin's HDD is ${spaceUsed}% full!"
  118. sendNotification
  119. fi
  120. # Check for most cpu intensive process, report if usage too high
  121. processName=`ps -e -o cp,args | sed -e 's/^[ \\t]*//' | awk -F " " '{print $1, $2}' | sed -e '1d' | sort -rn | head -1 | awk '{print $2}'`
  122. processUsage=`ps -e -o cp,args | sed -e 's/^[ \\t]*//' | awk -F " " '{print $1, $2}' | sed -e '1d' | sort -rn | head -1 | awk '{print $1}'`
  123. if [ $processUsage -gt $maxCpuUsage ]; then
  124. processUsage=`echo "${processUsage} / 10.0" | bc -q`
  125. message="${processName} needs ${processUsage}% CPU!"
  126. sendNotification
  127. fi
  128. </pre>
  129. <div id="disqus_thread"></div>
  130. <script type="text/javascript">
  131. var disqus_shortname = "xythobuz";
  132. (function() {
  133. var dsq = document.createElement("script"); dsq.type = "text/javascript"; dsq.async = true;
  134. dsq.src = "http://" + disqus_shortname + ".disqus.com/embed.js";
  135. (document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(dsq);
  136. })();
  137. </script>
  138. <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
  139. <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
  140. </div>
  141. <div class="nav">
  142. <h3>Thomas Buck</h3>
  143. <div id="logo"><img id="logo" src="http://www.gravatar.com/avatar/8d18fec40a74782052fb4c007d212475?s=180" alt="Avatar"></div>
  144. <p id="bio">
  145. 19 year old Information Engineering student from Germany.
  146. Making cool stuff, mostly with AVR microcontrollers.
  147. </p>
  148. <iframe src="http://githubbadge.appspot.com/badge/xythobuz?a=0" style="border: 0;height: 142px;width: 200px;overflow: hidden;" frameBorder=0></iframe>
  149. <ul id="menuList">
  150. <li><a href="/index.html">Home</a></li>
  151. <li><a href="/blog.html">Blog</a></li>
  152. <li><a href="/contact.html">Contact</a></li>
  153. <br>
  154. <li><a href="/ledcube.html">8x8x8 LED Cube</a></li>
  155. <li><a href="/yasab.html">YASAB AVR Bootloader</a></li>
  156. <li><a href="/avrnetstack.html">avrNetStack</a></li>
  157. <li><a href="/avrserial.html">AVR Serial Library</a></li>
  158. <li><a href="/serialdebug.html">Serial Debug</a></li>
  159. <li><a href="/ledmatrix.html">LED Matrix</a></li>
  160. <li><a href="/ssop28.html">SSOP28 - DIL Adapter</a></li>
  161. <li><a href="/xyrobot.html">xyRobot</a></li>
  162. <li><a href="/bluetooth.html">Bluetooth UART (BTM-222)</a></li>
  163. <li><a href="/k6x4008.html">K6x4008 SRAM</a></li>
  164. <li><a href="/xyrobotremote.html">xyRobotRemote</a></li>
  165. <li><a href="/rremote.html">rRemote</a></li>
  166. <br>
  167. <li><a href="/c250.html">Mio C250 Unlock</a></li>
  168. <li><a href="/nas.html">IB-NAS6210 Linux</a></li>
  169. <li><a href="/ultimatenotifier.html">Ultimate Notifier Script</a></li>
  170. <li><a href="/serialhelper.html">Serial Helper</a></li>
  171. </ul>
  172. <div id="recent">
  173. Recent blog posts:
  174. <ul id="recentList">
  175. <li class="recentList"><a href="/2013_03_25_doxygen.html">xyControl Doxygen Dokumentation</a></li><li class="recentDate">2013-03-25</li>
  176. <li class="recentList"><a href="/2013_03_16_pid.html">xyCopter PID-Parameter</a></li><li class="recentDate">2013-03-16</li>
  177. <li class="recentList"><a href="/2013_03_13_test_rig.html">Quadrocopter Test Rig Video</a></li><li class="recentDate">2013-03-13</li>
  178. <li class="recentList"><a href="/2013_03_12_test_rig.html">Quadrocopter Testvorrichtung</a></li><li class="recentDate">2013-03-12</li>
  179. <li class="recentList"><a href="/2013_03_10_yasab.html">xyCopter loves YASAB</a></li><li class="recentDate">2013-03-10</li>
  180. </ul>
  181. </div>
  182. </div>
  183. </div></div>
  184. <img id="dude" alt="The Dude" src="/img/dude.png">
  185. <div id="footer">
  186. Built with <a href="http://bitbucket.org/obensonne/poole">Poole</a>
  187. &middot;
  188. Licensed as <a href="http://creativecommons.org/licenses/by/3.0">CC-BY</a>
  189. &middot;
  190. <a href="http://validator.w3.org/check?uri=referer">Validate HTML</a>
  191. &middot;
  192. <a href="http://jigsaw.w3.org/css-validator/validator?uri=xythobuz.org%2Fstyle.css&amp;profile=css3">Validate CSS</a>
  193. &middot;
  194. <a href="http://feed1.w3.org/check.cgi?url=http://www.xythobuz.org/rss.xml">Validate RSS</a>
  195. &middot;
  196. <a href="http://www.validome.org/google/validate?url=http://www.xythobuz.org&amp;googleTyp=SITEMAP">Validate Sitemap</a>
  197. </div>
  198. <script src="http://gitforked.com/api/1.1/button.js" type="text/javascript"></script>
  199. </body>
  200. </html>