Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Computer as alarm clock -UPDATED 07-15-2004-
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
roothorick
Tux's lil' helper
Tux's lil' helper


Joined: 30 May 2004
Posts: 83
Location: Menasha, WI

PostPosted: Tue Jul 13, 2004 2:24 am    Post subject: Computer as alarm clock -UPDATED 07-15-2004- Reply with quote

Want to wake up to your own tunes instead of that annoying BLEEP! BLEEP! BLEEP! BLEEP! each morning? Something similar to my setup might work for you:

I have a cronjob that automatically boots a custom X session at my desired time, starting: an aterm running screen, Skype, XMMS, Mozilla, GKrellM, my specialty XMMS script (below), and finally Ion2. The script starts XMMS playing, and sets the volume to 0, then gradually ramping it up to maximum.

Here's the crontab line itself:
Code:
 0 7 * * * PATH=$PATH:/usr/X11R6/bin /usr/X11R6/bin/startx /home/roothorick/.xinitrc.auto &> /dev/null

Why the PATH reassignment? Cron apparently ignores /etc/profile and as a result, the /usr/X11R6/bin necessary for the startx script to work isn't in your PATH. There's probably some cleaner way to do this but I'm lazy and it's at the time of this update 0:30. Finally, why redirect to /dev/null? Do you want an e-mail transcript of your entire X session? That, and it doesn't run correctly here for some reason without it.

In case you're wondering where XMMS et. al. are coming from, here's the contents of /home/roothorick/.xinitrc.auto:
Code:
#!/bin/bash
xmodmap /etc/X11/xinit/.Xmodmap
xsetbg ~/.wp.png
xlock &
xmms &
python ~/.xmmsalarm.py &
gkrellm2 &
aterm -bg black -fg white -tr +sb -e screen -R &
voip/skype/skype &
xmms &
mozilla &
exec ion2

This is my normal X session, except that XMMS is started early, and the script gradually increasing XMMS's volume is also run (whereas for a normal session startup it wouldn't.)

Anywhoo, here's that script: (it's Python, so put it in a .py and run it)
Code:
import time, xmms

MINSTOMAX = 15 # Amount of time from silence to max volume

while xmms.get_info()[0] < 0:
    time.sleep(0.1) # Give it a chance to start damnit!
    continue

xmms.play()

volpersec = 89.0/float(MINSTOMAX*(60*10))

xmms.set_balance(0) # So that reading the main volume won't be skewed

vol = 1
while vol <= 90:
    if int(vol) != xmms.get_main_volume():
        xmms.set_main_volume(int(vol))
    time.sleep(0.1)
    vol += volpersec

It's worthy to note that the script terminates upon setting XMMS to a volume of 90%.

Almost forgot, you need PyXMMS installed for it to work (emerge pyxmms).

Then I log out, and leave my speakers on as I go to bed. Gnight ;)


Last edited by roothorick on Thu Jul 15, 2004 4:39 pm; edited 3 times in total
Back to top
View user's profile Send private message
Gherald2
Guru
Guru


Joined: 02 Jul 2003
Posts: 326
Location: Madison, WI USA

PostPosted: Tue Jul 13, 2004 3:41 am    Post subject: Re: Computer as alarm clock Reply with quote

roothorick wrote:
I have a cronjob that automatically boots a custom X session at my desired time, starting: an aterm running screen, Skype, XMMS, Mozilla, GKrellM, my specialty XMMS script (below), and finally Ion2.


Could you paste it as well?

EDIT: Thanks.
_________________
Unregistered Linux User #17598363


Last edited by Gherald2 on Thu Jul 15, 2004 5:43 am; edited 1 time in total
Back to top
View user's profile Send private message
John5788
Advocate
Advocate


Joined: 06 Apr 2004
Posts: 2140
Location: 127.0.0.1

PostPosted: Tue Jul 13, 2004 5:06 am    Post subject: Reply with quote

meh.. rtfm u lazy bastard :lol:
_________________
John5788
Back to top
View user's profile Send private message
Gherald2
Guru
Guru


Joined: 02 Jul 2003
Posts: 326
Location: Madison, WI USA

PostPosted: Tue Jul 13, 2004 5:44 am    Post subject: Reply with quote

I understand how crontab works, but I'd like to know what command(s) his cronjob executes to start all that shit.

Not an RTFM question; more like curiosity.
_________________
Unregistered Linux User #17598363
Back to top
View user's profile Send private message
vdboor
Guru
Guru


Joined: 03 Dec 2003
Posts: 592
Location: The Netherlands

PostPosted: Tue Jul 13, 2004 10:43 am    Post subject: Reply with quote

Cron is a daemon that should be running in the background... From the install guide, you might have installed something like vixie-cron. It is also the thing that starts "updatedb" at 4AM, or if you turn on your computer in the morning.

Instead of using xmms, it might be an idea to start mpg123 or mplayer -really-quiet -shuffle*.mp3 from the cronjob, since this doesn't require you to stay logged into KDE/GNOME all the time... ;)
_________________
The best way to accelerate a windows server is by 9.81M/S²
Linux user #311670 and Yet Another Perl Programmer

[ screenies | Coding on KMess ]
Back to top
View user's profile Send private message
allucid
Veteran
Veteran


Joined: 02 Nov 2002
Posts: 1314
Location: atlanta

PostPosted: Tue Jul 13, 2004 1:17 pm    Post subject: Reply with quote

for those of you who are less ambitious you could just 'emerge xmms-alarm' and control it from there. you have to be logged into X to use this...
Back to top
View user's profile Send private message
roothorick
Tux's lil' helper
Tux's lil' helper


Joined: 30 May 2004
Posts: 83
Location: Menasha, WI

PostPosted: Tue Jul 13, 2004 2:23 pm    Post subject: Reply with quote

allucid wrote:
for those of you who are less ambitious you could just 'emerge xmms-alarm' and control it from there. you have to be logged into X to use this...


Exactly my issue. I don't want X running all the time.

Anyway, I have in my home directory .xinitrc.auto that is just a customized xinitrc. The cronjob simply calls startx with that xinitrc.
Back to top
View user's profile Send private message
vdboor
Guru
Guru


Joined: 03 Dec 2003
Posts: 592
Location: The Netherlands

PostPosted: Tue Jul 13, 2004 7:07 pm    Post subject: Reply with quote

roothorick wrote:
Exactly my issue. I don't want X running all the time.

Anyway, I have in my home directory .xinitrc.auto that is just a customized xinitrc. The cronjob simply calls startx with that xinitrc.


I'm repeating myself now.. :oops: , but I'm really wondering.. if you even start X from a cronjob, wouldn't it be a better idea to start mplayer in the console with a small playlist..?

Just an idea, but launching X for an alarm is a little excessive imho.. :P
_________________
The best way to accelerate a windows server is by 9.81M/S²
Linux user #311670 and Yet Another Perl Programmer

[ screenies | Coding on KMess ]
Back to top
View user's profile Send private message
spindle
Apprentice
Apprentice


Joined: 01 Dec 2003
Posts: 243

PostPosted: Tue Jul 13, 2004 7:44 pm    Post subject: Reply with quote

Gherald wrote:
I understand how crontab works, but I'd like to know what command(s) his cronjob executes to start all that shit.

Not an RTFM question; more like curiosity.


um, i think Gherald wanted to know how roothorick's crontab is setup to do this, not what cron is. Seems like an appropriate question to me.
Back to top
View user's profile Send private message
John5788
Advocate
Advocate


Joined: 06 Apr 2004
Posts: 2140
Location: 127.0.0.1

PostPosted: Tue Jul 13, 2004 7:45 pm    Post subject: Reply with quote

welll as he says up there, it launches X, launches aterm, skype, xmms, mozilla, gkrellm, and ion2. it loads up him whole desktop ready for him to use it when he wakes in the morning.
_________________
John5788
Back to top
View user's profile Send private message
spindle
Apprentice
Apprentice


Joined: 01 Dec 2003
Posts: 243

PostPosted: Wed Jul 14, 2004 4:15 pm    Post subject: Reply with quote

perhaps i misunderstand here, but does this mean something like...

Code:

0 5 * * * startx
0 5 * * * aterm
0 5 * * * skype
0 5 * * * xmms
0 5 * * * mozilla
0 5 * * * gkrellm
0 5 * * * ion2
0 5 * * * wakescript.py


now i'm getting curious.
Back to top
View user's profile Send private message
roothorick
Tux's lil' helper
Tux's lil' helper


Joined: 30 May 2004
Posts: 83
Location: Menasha, WI

PostPosted: Thu Jul 15, 2004 5:27 am    Post subject: Reply with quote

Oh goodness no! I've just updated my original post with the SINGLE crontab line, and my beefy custom xinitrc (which is only one line longer than my normal xinitrc -- I'm a man that likes a big automated todo when X starts ;) )
_________________
Note: This user has been arrested under the DMCA for copyright infringement based on a complaint from The Inernational Cliche Company. He is also facing charges for violating US patents describing the encoding of text in digital form.
Back to top
View user's profile Send private message
Gherald2
Guru
Guru


Joined: 02 Jul 2003
Posts: 326
Location: Madison, WI USA

PostPosted: Thu Jul 15, 2004 7:21 am    Post subject: Reply with quote

Excellent; very nice indeed. It's 0200 so I won't try this out tonight, but soon :)

I don't know about you guys but I love getting cool ideas from others' config files.

In fact I started a thread about it.
_________________
Unregistered Linux User #17598363
Back to top
View user's profile Send private message
roothorick
Tux's lil' helper
Tux's lil' helper


Joined: 30 May 2004
Posts: 83
Location: Menasha, WI

PostPosted: Thu Jul 15, 2004 7:51 pm    Post subject: Reply with quote

vdboor wrote:
I'm repeating myself now.. :oops: , but I'm really wondering.. if you even start X from a cronjob, wouldn't it be a better idea to start mplayer in the console with a small playlist..?

Just an idea, but launching X for an alarm is a little excessive imho.. :P


My setup does more than run X and XMMS. It starts my entire X session so it's ready to go when I get up and sit down at my computer.
_________________
Note: This user has been arrested under the DMCA for copyright infringement based on a complaint from The Inernational Cliche Company. He is also facing charges for violating US patents describing the encoding of text in digital form.
Back to top
View user's profile Send private message
Frodo42
Tux's lil' helper
Tux's lil' helper


Joined: 21 Aug 2003
Posts: 119
Location: Bjerringbro, Denmark

PostPosted: Tue Jul 26, 2005 11:14 pm    Post subject: Reply with quote

Thanks you guys, this post is just what I was looking for.
I need to get up in 6 hours for a test and need to get as much sleep before that as possible as I am severe lack right now.
I only have my computer here, not even an ordinary alarm clock.
I just started emerging the easy solution, xmms-alarm that should do the trick for now, I'll try the cron thing later when I don't need my sleep so badly, this really looks cool 8)
_________________
my blog, my homepage
Back to top
View user's profile Send private message
Nuteater
Apprentice
Apprentice


Joined: 25 Sep 2003
Posts: 193
Location: Jyväskylä, Finland

PostPosted: Wed Jul 27, 2005 12:46 pm    Post subject: Reply with quote

For a simpler setup (and if you don't want to start X), you could always use
a non-X player such as mpg321, ogg123 or MPD. Also remember to tweak
the cron file to not wake you up on holidays. :wink: For a one-time-only
alarm you could use sys-process/at.
_________________
I am Nuteater, hear me roar.
Back to top
View user's profile Send private message
jamapii
Guru
Guru


Joined: 16 Sep 2004
Posts: 545

PostPosted: Fri Jul 29, 2005 9:59 am    Post subject: Reply with quote

Code:
(echo "$1"|grep -q :) && {
  i=$(echo "$1"|sed 's/\([0-9]*\):\([0-9]*\)/\2 \1/')
  echo "$i"|grep -E -q '[0-9][0-9]? [0-9][0-9]?' || exit
  crontab -l|sed '/_ALARMCLOCK_/s/ *[0-9][0-9]*  *[0-9][0-9]*/'"$i/" > ~/ct.$$
  crontab ~/ct.$$
  rm ~/ct.$$
}


a script fragment to change a crontab line marked by _ALARMCLOCK_. Lt needs a time in 24-hour format. It creates a temp file in the home directory.

The crontab line can be another script that repeats a song until you kill it.

Typing 1 or 2 correct kill commands is hopefully enough to wake you up :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum