Nolhay's Homebrew Morning Bash Alarm

From STNY LUG Wiki

Jump to: navigation, search

Intro

I use this Bash Script to wake up in the morning

The Code

#!/bin/bash

#Sources
WBNG='http://24.97.223.13/wbng2/closings/sch.html'
LOCAL='/home/Einstein/sch.html'
MSTR_SOURCE="$WBNG"
DUMP='/home/Einstein/closings_dump'
#End Sources

#Find a One Hour Delay
function check_one
{
	if [ "$( grep -i "ChenangoForks" $DUMP )" = "ChenangoForksSchoolDistrictOneHourDelay" ] ;then
		if [ "$(date +%H%M)" -ge 0530 ] && [ "$(date +%H%M)" -le 0600 ]; then
			sleep 1h
			rm $DUMP
			check_one
		fi
		if [ "$(date +%H%M)" -ge 0630 ] && [ "$(date +%H%M)" -le 0700 ]; then
			start_day
		fi
	else
			check_two
	fi
}
#End One Hour Delay

#Find a Two Hour Delay
function check_two
{
	if [ "$( grep -i "ChenangoForks" $DUMP )" = "ChenangoForksSchoolDistrictTwoHourDelay" ] ;then
		if [ "$(date +%H%M)" -ge 0530 ] && [ "$(date +%H%M)" -le 0600 ]; then
			sleep 2h
			rm $DUMP
			check_one
		fi
		if [ "$(date +%H%M)" -ge 0630 ] && [ "$(date +%H%M)" -le 0700 ]; then
			sleep 1h
			rm $DUMP
			check_one
		fi
		if [ "$(date +%H%M)" -ge 0730 ] && [ "$(date +%H%M)" -le 0800 ]; then
			start_day
		fi
	else
			check_close
	fi
}
#End Two Hour Delay

#Find a Cancellation
function check_close
{
	if [ "$( grep -i "ChenangoForks" $DUMP )" = "ChenangoForksSchoolDistrictClosed" ] ;then
		rm $DUMP
		exit 0
	else
		start_day
	fi
}
#End Cancellation

#No Delay
function start_day
{
####START MORNING#####
	#Turn monitors & music on; adjust volume
		xset dpms force on
		dcop kmix Mixer0 setMasterVolume 50
		dcop amarok player setVolume 50
		amarok --play
	#Open today's weather page
		firefox "http://www.wunderground.com/cgi-bin/findweather/getForecast?query=13744"
	#wait till I get out of shower
		sleep 15m
		dcop kmix Mixer0 setMasterVolume 50
	#This runs at X:00 Turn monitors & music off
		sleep 60m
		amarok --stop
		xset dpms force off
	#Clean up, clean up everybody do their share
		rm $DUMP
		exit 0
}

if [ "$(date +%H%M)" -ge 0530 ] && [ "$(date +%H%M)" -le 0800 ]; then
	#Log results
	echo "$(date +%x@%X) success" >> .sch_grep_results.txt
	#Create a dumpfile
	w3m -dump $MSTR_SOURCE | tr -d [:blank:] > $DUMP
	#Begin Delay Checking
	check_one 
else
	#Log results
	echo "$(date +%x@%X) ***FAILED***" >> .sch_grep_results.txt
	exit 0
fi
Personal tools