123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>Ultimate Notifier Script (#) xythobuz.de</title>
- <meta name="description" content="Sending Push Notifications to an iPhone from a Bash Script" />
- <meta name="keywords" content="xythobuz" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <link rel="author" href="/xythobuz@xythobuz.de">
- <link rel="shortcut icon" href="/img/favicon.ico">
- <link rel="alternate" type="application/rss+xml" title="Blog" href="/rss.xml">
- <link type="text/css" rel="stylesheet" href="/css/sh_bright.min.css" />
- <link rel="stylesheet" href="/css/bootstrap.css" type="text/css" media="screen" />
- <link rel="stylesheet" href="/css/gh-fork-ribbon.css" />
- <link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
- <script type="text/javascript" src="/js/sh_main.js"></script>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
- <script type="text/javascript" src="/js/bootstrap.js"></script>
- <script type='text/javascript'>
- /* <![CDATA[ */
- (function() {
- var s = document.createElement('script');
- var t = document.getElementsByTagName('script')[0];
- s.type = 'text/javascript';
- s.async = true;
- s.src = '//api.flattr.com/js/0.6/load.js?mode=auto&uid=xythobuz&category=text';
- t.parentNode.insertBefore(s, t);
- })();
- /* ]]> */
- </script>
- </head>
- <body onload="sh_highlightDocument('/js/sh/', '.min.js');">
-
- <div class="navbar">
- <div class="navbar-inner">
- <a class="brand" href="http://xythobuz.de/lastmusic">♫</a>
- <ul class="nav">
- <li><a href="/index.html">Home</a></li>
- <li><a href="/blog.html">Blog</a></li>
- <li><a href="/contact.html">Contact</a></li>
- <li class="dropdown"><a href="/software.html" class="dropdown-toggle" data-toggle="dropdown">Software<b class="caret"></b></a><ul class="dropdown-menu">
- <li><a href="/avrnetstack.html">avrNetStack</a></li>
- <li><a href="/avrserial.html">AVR Serial Library</a></li>
- <li><a href="/c250.html">Mio C250 Unlock</a></li>
- <li><a href="/nas.html">IB-NAS6210 Linux</a></li>
- <li><a href="/serialhelper.html">Serial Helper</a></li>
- <li><a href="/ultimatenotifier.html">Ultimate Notifier Script</a></li>
- <li><a href="/yasab.html">YASAB AVR Bootloader</a></li>
- </ul>
- <li class="dropdown"><a href="/hardware.html" class="dropdown-toggle" data-toggle="dropdown">Hardware<b class="caret"></b></a><ul class="dropdown-menu">
- <li><a href="/ledcube.html">8x8x8 LED Cube</a></li>
- <li><a href="/xycontrol.html">xyControl</a></li>
- <li class="dropdown-submenu"><a href="/xyrobot.html" class="dropdown-toggle" data-toggle="dropdown">xyRobot</a><ul class="dropdown-menu">
- <li><a href="/bluetooth.html">Bluetooth UART (BTM-222)</a></li>
- <li><a href="/k6x4008.html">K6x4008 SRAM</a></li>
- <li><a href="/rremote.html">rRemote</a></li>
- <li><a href="/xyrobotremote.html">xyRobotRemote</a></li>
- </ul>
- <li><a href="/ssop28.html">SSOP28 - DIL Adapter</a></li>
- <li><a href="/serialdebug.html">Serial Debug</a></li>
- <li><a href="/ledmatrix.html">LED Matrix</a></li>
- </ul>
- </ul>
- </div>
- </div>
-
- <div id="header">
- <h1>xythobuz.de</h1>
- <p><a href="http://xythobuz.de/lastmusic">♫</a></p>
- <h2>Ultimate Notifier Script</h2>
- </div>
-
- <div class="btn-group"><a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Language<span class="caret"></span></a><ul class="dropdown-menu">
- <li><a href='Ultimate Notifier Script'>title_de</a></li> | <li><a href='notifier'>compat</a></li> | <li><a href='true'>reddit</a></li> | <li><a href='Sending Push Notifications to an iPhone from a Bash Script'>description</a></li> | <li><a href='software'>parent</a></li> | <li><a href='Ultimate Notifier Script'>title</a></li> | <li><a href='ultimatenotifier.de.html'>url</a></li> | <li><a href='xythobuz'>twitter</a></li> | <li><a href='true'>comments</a></li> | <li><a href='de'>lang</a></li> | <li><a href='{u'de': u'ultimatenotifier.de.html', 'en': u'ultimatenotifier.html'}'>lang_links</a></li> | <li><a href='./input/ultimatenotifier.de.md'>fname</a></li> | <li><a href='[u'de', 'en']'>other_lang</a></li> | <li><a href='true'>print</a></li> | <li><a href='5'>position</a></li> | <li><a href='true'>flattr</a></li>
- </ul></div>
-
- <div id="content">
- <h1>Ultimate Notifier Script</h1>
- <p>Der Dienst <a href="http://ultimatenotifier.com/">Ultimate Notifier</a> erlaubt es relativ problemlos, zum Beispiel mittels curl Push-Notifications an ein iPhone zu senden. Darauf basierend können Shell Skripte geschrieben werden, welche regelmäßig als Cron-Job gestartet werden. So kann man sich zum Beispiel über eine geänderte Public IP informieren lassen. Dafür muss dieses Skript irgendwo gespeichert werden:</p>
- <pre class="sh_sh">
- #!/bin/sh
-
- ipfile=".currentip"
- service="ifconfig.me"
- user="username"
- pass="password"
- message="IP:"
-
- ip=`curl -s $service`
- touch $ipfile
- lastip=`cat $ipfile`
- if [ "$ip" != "$lastip" ]; then
- echo "New public IP. Sending notification!"
- curl -s "https://www.ultimatenotifier.com/items/User/send/${user}/message=${message}%20${ip}/password=${pass}"
- fi
- cp /dev/null $ipfile
- echo $ip > $ipfile
- </pre>
-
- <p>Es liest die aktuelle öffentliche IP mittels curl vom Dienst <a href="http://ifconfig.me">ifconfig.me</a> aus und vergleicht diese mit der zwischengespeicherten IP in einer Datei namens .currentip. Unterscheiden sich die IPs, wird eine Push Notification gesendet und die neue IP gespeichert.</p>
- <p>Mit dem Befehl</p>
- <pre>crontab -e</pre>
-
- <p>Kann ein Eintrag ins cronfile hinzugefügt werden, sodass das Skript regelmäßig gestartet wird. Ein Beispiel, für 30 Minuten:</p>
- <pre>*/30 * * * * /Users/anon/bin/ipnotify.sh</pre>
-
- <p>Der Code findet sich auch auf <a href="https://github.com/xythobuz/Snippets/blob/master/ipnotify.sh">GitHub</a>.</p>
- <p>Natürlich kann dieses Prinzip beliebig erweitert werden. Dieses Bash Skript wird auf meinem Server alle 5 Minuten von cron gestartet und berichtet über eventuelle Probleme.</p>
- <pre class="sh_sh">
- #!/bin/bash
-
- # Checks for Health of Server and sends notifications to iPhone in case of error
- # Checks for:
- # - HDD Temperature
- # - HDD Space
- # - CPU Usage
- # Sends a notification via UltimateNotifier
- # Depends on bash, wget, hddtemp, grep, awk, sed, ps, sort and head.
-
- # ------------------------------
- # ------------------------------
-
- # Your UltimateNotifier Password
- UNUsername="YourUserName"
- UNPassword="YourPassWord"
-
- # Check for free space
- hddMountPoint="bay" # greps for this in mounted hdds
- maxPercentFull=75 # minimum percentage to send notification
-
- # Check for CPU Usage of processes
- maxCpuUsage=750 # Is in tenths of a percent (420 => 42%)
-
- # Checks hdd temperature
- # Depends on hddtemp tool
- hddDevice="/dev/sda"
- maxHddTemp=50
-
- # ------------------------------
- # ------------------------------
-
- # Set $message to your Message and then call this...
- function sendNotification {
- wget "https://www.ultimatenotifier.com/items/User/send/${UNUsername}/message=${message}/password=${UNPassword}" -O /dev/null -q
- echo "$message"
- }
-
- # ------------------------------
- # ------------------------------
-
- # Check for hdd temperature
- hddTemp=`/usr/sbin/hddtemp ${hddDevice} | awk '{print $4}' | awk -F '°' '{print $1}'`
- if [ $hddTemp -gt $maxHddTemp ]; then
- message="Marvin's HDD has reached ${hddTemp}°C!"
- sendNotification
- fi
-
- # Check for free space on hdd
- spaceUsed=`df -h | grep ${hddMountPoint} | awk '{print $5}' | sed 's/%//'`
- if [ $spaceUsed -gt $maxPercentFull ]; then
- message="Marvin's HDD is ${spaceUsed}% full!"
- sendNotification
- fi
-
- # Check for most cpu intensive process, report if usage too high
- 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}'`
- 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}'`
- if [ $processUsage -gt $maxCpuUsage ]; then
- processUsage=`echo "${processUsage} / 10.0" | bc -q`
- message="${processName} needs ${processUsage}% CPU!"
- sendNotification
- fi
- </pre>
- <span id="flattr">
- <a class="FlattrButton" href="http://www.xythobuz.de/ultimatenotifier.de.html" title="Ultimate Notifier Script">Sending Push Notifications to an iPhone from a Bash Script</a>
- </span>
- <span id="twitter">
- <a href="https://twitter.com/share" class="twitter-share-buttdata-via="xythobuz" data-dnt="true" data-related="xythobuz" data-count="vertical">Tweet</a><script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s;if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twi.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitwjs");</script>
- </span>
- <span id="reddit">
- <script type="text/javascript">reddit_url = "http://www.xythobuz.de/ultimatenotifier.de.html";</script>
- <script type="text/javascript" src="http://www.redcom/static/button/button2.js"></script>
- </span>
- <div id="print"><script>var pfHeaderImgUrl = '';var pfHeaderTagline = '';var pfdisableClickToDel = 0;var pfHideImages = 0;var pfImageDisplayStyle = 'right';var pfDisablePDF = 0;var pfDisableEmail = 0;var pfDisablePrint = 0;var pfCustomCSS = '';var pfBtVersion='1';(function(){var js, pf;pf = document.createElement('script');pf.type = 'text/javascript';if('https:' == document.location.protocol){js='https://pf-cdn.printfriendly.com/ssl/main.js'}else{js='http://cdn.printfriendly.com/printfriendly.js'}pf.src=js;document.getElementsByTagName('head')[0].appendChild(pf)})();</script><a href="http://www.printfriendly.com" style="color:#6D9F00;text-decoration:none;" class="printfriendly" onclick="window.print();return false;" title="Printer Friendly and PDF"><img style="border:none;margin:0 6px" src="https://pf-cdn.printfriendly.com/images/icons/pf-print-icon.gif" width="16" height="15" alt="Print Friendly Version of this page" />Print <img style="border:none;margin:0 6px" src="https://pf-cdn.printfriendly.com/images/icons/pf-pdf-icon.gif" width="12" height="12" alt="Get a PDF version of this webpage" />PDF</a></div>
- <div id="disqus_thread"></div>
- <script type="text/javascript">
- var disqus_shortname = "xythobuz";
- (function() {
- var dsq = document.createElement("script"); dsq.type = "text/javascript"; dsq.async = true;
- dsq.src = "http://" + disqus_shortname + ".disqus.com/embed.js";
- (document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0] ).appendChild(dsq);
- })();
- </script>
- <noscript>Please enable JavaScript to view the <a href="http://disqus. com/?ref_noscript">comments powered by Disqus.</a></noscript>
- <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
- </div>
-
- <div style="color: gray; text-align: center;">
- Built with <a href="http://bitbucket.org/obensonne/poole">Poole</a>
- ·
- Made with <a href="http://twitter.github.io/bootstrap/index.html">Bootstrap</a>
- ·
- Using <a href="http://shjs.sourceforge.net">SHJS</a>
- ·
- Licensed as <a href="http://creativecommons.org/licenses/by/3.0">CC-BY</a>
- </div>
- <img src="/stats/count.php?img" alt="Analytics">
- <script src="http://gitforked.com/api/1.1/button.js" type="text/javascript"></script>
- <script type="text/javascript">
- var _gaq = _gaq || [];
- _gaq.push(['_setAccount', 'UA-39163591-1']);
- _gaq.push(['_setDomainName', 'xythobuz.org']);
- _gaq.push(['_setAllowLinker', true]);
- _gaq.push(['_trackPageview']);
- (function() {
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
- })();
- </script>
- </body>
- </html>
|