#!/usr/bin/python
import time
from time import sleep
import os
import sys
import subprocess
from subprocess import Popen
import pynma
import re
import commands
import urllib2
ips = commands.getoutput("/sbin/ifconfig | grep -i \"inet\" | grep -iv \"inet6\" | " + "awk {'print $2'$
ips = ips +"\n"+ urllib2.urlopen('http://ip.42.pl/raw').read()
print ips
p = pynma.PyNMA( "NOTIFYMYANDROIDAPIKEYHERE" )
application="boot Alert"
event="pi just booted"
p.push(application, event, ips)
Tuesday, February 11, 2014
Sunday, February 9, 2014
/usr/local/timelapse/capture.sh
#!/bin/bash
#kill old procs
vidpid=$(pgrep raspivid)
if ! kill $vidpid > /dev/null 2>&1; then
echo "no raspivid running OK" >&2
fi
SAVEROOT="/var/www/vids"
YEARDIR=$(date +%Y)
MONTHDIR=$(date +%m)
SAVEDIR="$SAVEROOT/$YEARDIR/$MONTHDIR"
filename=$(date +"%Y_%m%d_%H%M-%S").h264
if [ ! -d "$SAVEROOT/$YEARDIR" ]; then
# if the year dir don't exist, make it
mkdir $SAVEROOT/$YEARDIR
fi
if [ ! -d "$SAVEROOT/$YEARDIR/$MONTHDIR" ]; then
# if the month dir don't exist, make it
mkdir $SAVEROOT/$YEARDIR/$MONTHDIR
fi
filename=$SAVEROOT/$YEARDIR/$MONTHDIR/$filename
raspivid -n -t 3600000 -fps 24 -o $filename
#kill old procs
vidpid=$(pgrep raspivid)
if ! kill $vidpid > /dev/null 2>&1; then
echo "no raspivid running OK" >&2
fi
SAVEROOT="/var/www/vids"
YEARDIR=$(date +%Y)
MONTHDIR=$(date +%m)
SAVEDIR="$SAVEROOT/$YEARDIR/$MONTHDIR"
filename=$(date +"%Y_%m%d_%H%M-%S").h264
if [ ! -d "$SAVEROOT/$YEARDIR" ]; then
# if the year dir don't exist, make it
mkdir $SAVEROOT/$YEARDIR
fi
if [ ! -d "$SAVEROOT/$YEARDIR/$MONTHDIR" ]; then
# if the month dir don't exist, make it
mkdir $SAVEROOT/$YEARDIR/$MONTHDIR
fi
filename=$SAVEROOT/$YEARDIR/$MONTHDIR/$filename
raspivid -n -t 3600000 -fps 24 -o $filename
Tuesday, January 28, 2014
/opt/isitdaytime.sh
yourzip="97205" # set this to your local zip code
request="http://www.almanac.com/astronomy/rise/zipcode"
thedate="$(date +%Y-%m-%d)"
url="$request/$yourzip/$thedate"
raw=$(curl --silent "$url" | grep rise_nextprev | cut -d\< -f35-40)
sunrise=$( echo $raw | cut -d" " -f3)
sunset=$( echo $raw | cut -d" " -f6)
srh=$(echo $sunrise | cut -d: -f1)
srm=$(echo $sunrise | cut -d: -f2)
ssh=$(echo $sunset | cut -d: -f1)
ssh=$(( $(echo $sunset | cut -d: -f1) + 12 ))
ssm=$(echo $sunset | cut -d: -f2)
echo "$sunrise sunrise"
echo "$ssh sunset hour"
## what's the hour now
hour=$(date +%H)
min=$(date +%m)
echo "$hour now"
if [ $hour -eq $srh -a $min -ge $srm ] ; then
echo "sunrise hour"
fi
if [ $hour -gt $srh -a $hour -lt $ssh ] ; then
echo "daytime"
fi
if [ $hour -eq $ssh -a $min -le $ssm ] ; then
echo "sunset hour"
fi
if [ $hour -gt $ssh ] ; then
echo "nighttime"
/opt/SunRiseSet.sh
#!/bin/sh
#
# Gets sunset / sunrise tables from aa.usno.navy.mil
# http://ubuntu.online02.com/node/36
# Run with cron after midnight but before sunrise (4am) to get the times for the day
# http://www.homeautomationhub.com/sites/default/files/suntimes.txt
City="Portland"
State="Oregon"
LatDeg="45"
LatMin="5"
LonDeg="122"
LonMin="7"
Year=$(date +%Y)
Month=$(date +%m)
Day=$(date +%d)
Dst=$(date +%z | sed 's/+0//' | sed 's/00//'| cut -d- -f2)
TempFile=/tmp/suntable$Year+$Dst.htm
SunRiseFile=/tmp/sunrise$Year$Month$Day.txt
SunSetFile=/tmp/sunset$Year$Month$Day.txt
# <input type="text" name="place" id="placeint" maxlength="32" value="(no name given)">
# <select name="type" id="tabtyb">
# <value="0">sunrise/sunset</option><value="1">moonrise/moonset</option>
# <value="2">civil twilight</option><value="3">nautical twilight</option><value="4">astronomical twilight</option>
# <fieldset><legend><b>Longitude:</b></legend>
# <input type="radio" name="xx0" id="east" value="1" id="west" value="-1">
# <input type="text" name="xx1" id="dego" name="xx2" id="mino">
# <fieldset><legend><b>Latitude:</b></legend>
# <input type="radio" name="yy0" id="north" value="1" id="south" value="-1">
# <input type="text" name="yy1" id="dega" name="yy2" id="mina">
# <fieldset><legend><b>Time Zone:</b></legend>
# <input type="radio" name="zz0" id="zeast" value="1" id="zwest" value="-1">
# <input type="text" name="zz1" id="zhour">
# wget http://aa.usno.navy.mil/cgi-bin/aa_pap.pl --post-data="xxy=$YEAR&xxm=$MONTH&xxd=$DAY&st=$STATE&place=$CITY" -O /tmp/suntable.htm
if [ ! -s $TempFile ]; then
wget http://aa.usno.navy.mil/cgi-bin/aa_pap.pl --post-data="type=0&zz0=-1&zz1=$Dst&xx0=-1&xx1=$LonDeg&xx2=$LonMin&yy0=1&yy1=$LatDeg&yy2=$LatMin&ID=AA&FFX=2&xxy=$Year&xxm=$Month&xxd=$Day&st=$State&placeus=$City&ZZZ=END" -O $TempFile
fi
SUNRISE=$(cat $TempFile | grep Sunrise | sed 's/Sunrise //' | sed 's/\.//g' | sed 's/ //g')
SUNSET=$(cat $TempFile | grep Sunset | sed 's/Sunset //' | sed 's/\.//g' | sed 's/ //g')
# SUNRISE=$(cat $TempFile | grep ^$Day | awk -v n=$Month '{print $(n*2)}')
# SUNSET=$(cat $TempFile | grep ^$Day | awk -v n=$Month '{print $(n*2+1)}')
echo Sunrise: $SUNRISE
echo Sunset: $SUNSET
echo $SUNRISE>$SunRiseFile
echo $SUNSET>$SunSetFile
# Run commands at sunrise or sunset
# at -f /path/to/script.sh $SUNRISE
# at -f /path/to/script.sh $SUNSET
/opt/spaceCheck.sh
#!/bin/sh
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge 90 ]; then
# echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
# mail -s "Alert: Almost out of disk space $usep%" you@uoy.com
sendemail -f "raspberry@pi.com" -t "you@uoy.com" -u "Alert: Almost out of disk space $usep%" -m "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" -s mailout.collegenet.com
fi
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge 90 ]; then
# echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
# mail -s "Alert: Almost out of disk space $usep%" you@uoy.com
sendemail -f "raspberry@pi.com" -t "you@uoy.com" -u "Alert: Almost out of disk space $usep%" -m "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" -s mailout.collegenet.com
fi
/opt/checkip.pl
#!/usr/bin/perl
$IP_FILE = "ipemail.result";
my $localip= `/sbin/ifconfig | grep "inet addr" | grep -v 127.0.0.1`;
my $newip = `/usr/bin/wget http://ifconfig.me/ip -O - -q`;
my $hostname = `hostname`;
my $oldip = getoldip();
my $send_to = "To: andys\@florapdx.com\n";
my $reply_to = "Reply-to: andys\@florapdx.com\n";
my $from = "From: andys\@florapdx.com\n";
my $subject = "Subject: IP Address: $newip\n";
my $content = "$hostname\n $newip\n $localip";
chomp($newip);
if($newip ne $oldip)
{
print "old ip >$oldip<\n";
writenewip($newip);
unless(open (MAIL, "|/usr/sbin/sendmail andys\@florapdx.com"))
{
print "error.\n";
warn "Error starting sendmail: $!";
}
else{
print MAIL $from;
print MAIL $reply_to;
print MAIL $subject;
print MAIL $send_to;
print MAIL "Content-type: text/html\n\n";
print MAIL $content;
close(MAIL) || warn "Error closing mail: $!";
print "Mail sent\n";
}
}
sub writenewip
{
my($newip) = @_;
print ("new IP = >$newip<\n");
open IPFILE, ">$IP_FILE";
print IPFILE "$newip";
close IPFILE;
}
sub getoldip
{
open IPFILE, "$IP_FILE";
my($line) = 0;
while ( <IPFILE> )
{
$line = $_;
chomp($line);
}
close IPFILE;
return($line);
}
$IP_FILE = "ipemail.result";
my $localip= `/sbin/ifconfig | grep "inet addr" | grep -v 127.0.0.1`;
my $newip = `/usr/bin/wget http://ifconfig.me/ip -O - -q`;
my $hostname = `hostname`;
my $oldip = getoldip();
my $send_to = "To: andys\@florapdx.com\n";
my $reply_to = "Reply-to: andys\@florapdx.com\n";
my $from = "From: andys\@florapdx.com\n";
my $subject = "Subject: IP Address: $newip\n";
my $content = "$hostname\n $newip\n $localip";
chomp($newip);
if($newip ne $oldip)
{
print "old ip >$oldip<\n";
writenewip($newip);
unless(open (MAIL, "|/usr/sbin/sendmail andys\@florapdx.com"))
{
print "error.\n";
warn "Error starting sendmail: $!";
}
else{
print MAIL $from;
print MAIL $reply_to;
print MAIL $subject;
print MAIL $send_to;
print MAIL "Content-type: text/html\n\n";
print MAIL $content;
close(MAIL) || warn "Error closing mail: $!";
print "Mail sent\n";
}
}
sub writenewip
{
my($newip) = @_;
print ("new IP = >$newip<\n");
open IPFILE, ">$IP_FILE";
print IPFILE "$newip";
close IPFILE;
}
sub getoldip
{
open IPFILE, "$IP_FILE";
my($line) = 0;
while ( <IPFILE> )
{
$line = $_;
chomp($line);
}
close IPFILE;
return($line);
}
crontab entries
#*/5 * * * * /usr/local/timelapse/capture.sh
15 1 * * * /opt/SunRiseSet.sh
10 0 * * * /opt/spaceCheck.sh
15 1 * * * /opt/SunRiseSet.sh
10 0 * * * /opt/spaceCheck.sh
add to /etc/rc.local
in /etc/rc.local add:
/opt/checkip.pl >/dev/null 2>&1
/opt/bootalert.py > /var/log/alert.log 2>&1
/opt/SunRiseSet.sh
/opt/checkip.pl >/dev/null 2>&1
/opt/bootalert.py > /var/log/alert.log 2>&1
/opt/SunRiseSet.sh
Subscribe to:
Posts (Atom)