Register
It is currently Sat Aug 30, 2014 4:19 am

(B)ash (A)larm (C)lock (S)cript


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Sat Jun 17, 2006 2:50 am   

Joined: Fri Oct 14, 2005 9:30 am
Posts: 61
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?


Top
 Profile WWW  
 PostPosted: Thu Jun 22, 2006 10:47 am   

Joined: Fri Oct 14, 2005 9:30 am
Posts: 61
BUMPS!!!
no ideas anyone?


Top
 Profile WWW  
 PostPosted: Fri Jun 23, 2006 10:51 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
ok... so i started out by editing your post... cause i just saw one or two errors.. then i realized... this is not... uh... gonna work.. :)

so here ya go:
Code:
#!/bin/bash
setime="$H $M"
soundit=0
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
}
alarm ()
{
the_time=`date "+%H %M"`
echo -ne "\b\b\b\b\b\b\b"
echo -ne "$the_time"
if [[ "$the_time" == "$H $M" ]]
then
   echo "Your alarm is going off!";
   mplayer ~/.alarm/alarm.mp3;
   soundit=1
   exit
else
        sleep .01
fi
}
setalarm ()
{
read -p "What hour (24h format - eg 13 hours is 1 pm) would you like the alarm to go off: " 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: " M
echo "Alarm is set for $H $M"
}
doesmplayer
direxist
mp3exist
setalarm
while (("$soundit" == "0"))
do
        alarm
done


it is structurally different... and a couple variables added... but it does what you want now... hope you enjoy :)


Top
 Profile  
 PostPosted: Fri Jun 23, 2006 1:14 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 666
Location: Des Moines, Iowa
Nice jbsnake ;)

indented and everything ....... :shock: :shock: :shock:

:lol: :lol: :lol: :lol:


Top
 Profile WWW  
 PostPosted: Wed Jun 28, 2006 11:48 am   

Joined: Fri Oct 14, 2005 9:30 am
Posts: 61
cheers jbsnake :)
I uploaded it to my scripts section and added a couple of changes:
1) Piped mplayer to /dev/null so you don't get all the mplayer junk on screen
2) set it so that the message "your alarm is going off" appears on a new line.
Thanks,
Rob.


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP