Ok my new bash project is setting an alarm clock script, here is what I have got for now:
Code:
#!/bin/bash
setime="$H $M"
direxist ()
{
if [[ -d ~/.alarm/ ]]
then
echo ""
else
mkdir ~/.alarm
fi
}
mp3exist ()
{
if [[ -e ~/.alarm/alarm.mp3 ]]
then
echo ""
else
echo "No alarm.mp3 found in ~/.alarm. Please copy an mp3 to the filename ~/.alarm/alarm.mp3";
exit
fi
}
doesmplayer ()
{
which mplayer &>/dev/null
if [ $? != "0" ];
then
echo -e "mplayer is not installed";
read -p "press enter to continue" var
exit;
fi
}
clock ()
{
delay1='sleep 1'
wipescreen='echo -ne \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\'
echo -ne "`date +"%H %M"`";$delay1 ;$wipescreen
alarm
}
alarm ()
{
the_time=`clock`
if [ "$the_time" == "$H $M" ]
then
echo "Your alarm is going off!";
mplayer ~/.alarm/alarm.mp3;
exit
else
clock
fi
}
setalarm ()
{
read -p "What hour (24h format - eg 13 hours is 1 pm) would you like the alarm to go off: " D # this should be H
read -p "How many minutes past the hour would you lke the alarm to go off (for on the hour put 00 and any number under 10 type 0 in front of it: " H # this should be M
echo "Alarm is set for $H $M"" # delete one of these quotation marks
clock
}
doesmplayer
direxist
mp3exist
setalarm
From running the script you will be able to see that it is not working properly, any ideas?