Днес имах малко свободно време и реших да напиша скрипта. Идеята на
Jet да използвам
cron и
at ми се стори най-лесна за реализиране, и затова се захванах с нея.
Ето го и самия скрипт:
GeSHi (Bash):
#!/bin/bash
WOEID="839722" # From weather.yahoo.com link for your city
# Get weather and dump into temp file
if $(wget --no-cache -q "http://weather.yahooapis.com/forecastrss?w=$WOEID" -O /tmp/time);
then
mv /tmp/time /tmp/sunset.TMP
fi
Sunrise=`cat /tmp/sunset.TMP | grep astronomy | sed -e 's/.*sunrise="//g' | sed -e 's/ .*//g'`
Sunset=`cat /tmp/sunset.TMP | grep astronomy | sed -e 's/.*sunset="//g' | sed -e 's/ .*//g'`
let hourSunset=`echo $Sunset | cut -d: -f1`+12
minuteSunset=`echo $Sunset | cut -d: -f2`
sunset24=$hourSunset:$minuteSunset;
# Converts the Sunrise to Timestamp with the current date
dateOnly=`date +'%Y-%m-%d '`; # Current date with space in the end
sunriseForStamp=$dateOnly$Sunrise:00;
sunriseStamped=`date -d "$sunriseForStamp" "+%s"`
# Converts the Sunset to Timestamp with the current date
sunsetForStamp=$dateOnly$sunset24:00;
sunsetStamped=`date -d "$sunsetForStamp" "+%s"`
# Converts Local time to Timestamp
localTime=`date +'%Y-%m-%d %H:%M:00'`;
localTimeStamped=`date -d "$localTime" "+%s"`
# Sunrise
if [ $localTimeStamped -le $sunriseStamped ]; then
redshiftgui
fi
# Sunset
if [ $localTimeStamped -lt $sunsetStamped ]; then
`echo "export DISPLAY=:0 && /usr/bin/redshiftgui" | at $sunset24 today`;
elif [ $localTimeStamped -ge $sunsetStamped ]; then
redshiftgui
fi
След това
пуснах един cron job на скрипта и всичко се автоматизира.
Като цяло ми беше доста полезно, защото понаучах синтакса на Bash.
Благодаря отново на всички отзовали се, без вашата помощ нямаше да успея да го напиша. Рядко се срещат печени хора като вас