#!/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 # # N 59:23:30.16, E 24:32:11.37 Place=Harkuj4rve LatDeg=59 LatMin=23 LonDeg=24 LonMin=32 Year=$(date +%Y) Month=$(date +%m) Day=$(date +%d) Dst=$(date +%z | sed 's/+0//' | sed 's/00//') TempFile=/tmp/suntable$Year+$Dst.htm SunTimesFile=/tmp/suntimes$Year$Month$Day.txt # # # #
Latitude: # # #
Time Zone: # # # 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_rstablew.pl?type=0&xxy=$Year&xx0=1&xx1=$LonDeg&xx2=$LonMin&yy0=1&yy1=$LatDeg&yy2=$LatMin&zz0=1&zz1=$Dst&place=$Place" -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 $SUNSET>$SunTimesFile # Run commands at sunrise or sunset # at -f /path/to/script.sh $SUNRISE # at -f /path/to/script.sh $SUNSET