Contab and mp3blaster -> Alarm Clock
It is 0150 right now, and you would have certainly guessed by now that I am not able to sleep and/or study. I have been passing my time surfing various things ans chatting on IRC and stuff. Now, however, I must sleep cause I have to attend a program tomorrow morning and also study a bit.
Before I go though, my alarm clock or I might say my cell-phone has failed to wake me up on time for ‘n’th time1. So, I decided to give it up and find a new way. My laptop is always on. I decided to give it a thought and try something. Then I came across ‘crontab’.
The crontab command, found in *nix systems, is used to schedule commands to be executed periodically or (in rare cases) at a specific singular time. It reads a series of commands from standard input and collects them into a file known as a “crontab” which is later read and whose instructions are carried out.
So, I decided to combine this with mp3blaster to get a alarm clock. What I did was simple. I created a shell script which opens a file ‘alarm.mp3′ from mp3blaster. The script is actually a single command. I wanted to learn to execute shell scripts in crontab so as to run anything I want (which won’t happen as every script is unique). I saved it under /home/aditya/bin. And ‘chmod’ed it to 755. That made the script executable.
The script is as follows,
#!/bin/bash mp3blaster /home/aditya/alarm.mp3
Thats all. Nothing much, but I could have loaded a playlist and played it at random… there are endless possibilities. Anyways, so, I did this and then I went to bash to set up a cron job.
The default text editor for crontab is vi/vim. I do not know any one of them. So, I decided to change the editor to gedit. So, I issued following commands.
export EDITOR="gedit" crontab -e
This opened the file crontab under gedit. Then I edited the first line to,
30 07 * * 1-6 env DISPLAY=:0 /usr/bin/gnome-terminal -x sh alarm.sh
And I saved the file and quit. And that was it. The alarm clock was set to execute the script alarm.sh at 0730 hours, every weekday and Saturday. Check the references for more information about the syntax of the cron job crontab entries.
Now, I am going to bed. I will wake up to the sounds of alarm.mp3 (I think I will keep the real song name to myself). Now go and create a crontab alarm for yourself.
References :-
- mp3blaster (my own article cum tutorial).
- Crontab - Dream Host.
- Debian - Administration.
Posts in the series, Going the CLI Way :-
- Where n is a natural number… or n = {0,1,2,…,n?2,n?1} = {0,1,2,…,n?2} ? {n?1} = (n?1) ? {n?1}… [↩]
This entry was posted on Sunday, April 27th, 2008 at 2:16 am and is filed under Console, HowTo, Linux, My Life, Tools. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.



Aditya May 11th, 2008 at 12:18 pm
^^ #$%@$#%#$… Can’t you understand such a simple thing? I mean, I have written that vi/vim are editors, and it obviously means that I know them. What I am yet to learn is the proper (or even improper) way to use them. x-(
And as for the alarm clock…. IT WORKS :p finally the laptop has been put to some use.