LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-24-2004, 11:02 PM   #1
ex0r
Member
 
Registered: Jun 2003
Posts: 36

Rep: Reputation: 15
Using cron to exec MP3 for alarm clock.


I've been searching of the forum for a task scheduler and I came across posts on cron. I just started using linux about 2 weeks ago and on Windows before I would schedule and mp3 every morning at 7am to wake me up. I'm not sure how to set this up I think use crontabs -e or something of that nature. Say the mp3 is in /usr/music , how would I exec this mp3 every morning? Thanks for the help.
 
Old 02-24-2004, 11:19 PM   #2
Demonbane
LQ Guru
 
Registered: Aug 2003
Location: Sydney, Australia
Distribution: Gentoo
Posts: 1,796

Rep: Reputation: 47
You probably want to put something like this in your crontab file:
Code:
0 7 * * * /usr/bin/mplayer /usr/music/mymp3.mp3
change the executable to whatever mp3 player you prefer.
 
Old 02-24-2004, 11:30 PM   #3
ex0r
Member
 
Registered: Jun 2003
Posts: 36

Original Poster
Rep: Reputation: 15
Ok, now that makes sense, I wasn't sure if you had to specify a program for it to run also. How do I go about editing that. Crontab -e brings up the text and 4 demos it looks like but I can't type, how can I edit it? Thank you
 
Old 02-24-2004, 11:34 PM   #4
Demonbane
LQ Guru
 
Registered: Aug 2003
Location: Sydney, Australia
Distribution: Gentoo
Posts: 1,796

Rep: Reputation: 47
I can't remember whats the default in Slackware, but it looks for the EDITOR variable.
eg
Code:
EDITOR="vi" crontab -e
will use vi to edit it, change it to your favorite text editor
 
Old 02-24-2004, 11:41 PM   #5
ex0r
Member
 
Registered: Jun 2003
Posts: 36

Original Poster
Rep: Reputation: 15
Hmm... I did that and it still just comes up in the console and I can't edit the text.
 
Old 02-24-2004, 11:47 PM   #6
Demonbane
LQ Guru
 
Registered: Aug 2003
Location: Sydney, Australia
Distribution: Gentoo
Posts: 1,796

Rep: Reputation: 47
press "i"
enter the contents
press ESC, then enter ":wq" (colon, w and q)
"crontab -l" and see if it's there
 
Old 02-24-2004, 11:55 PM   #7
ex0r
Member
 
Registered: Jun 2003
Posts: 36

Original Poster
Rep: Reputation: 15
Ok, I have something like this but nothing seems to be working...
Code:
# Run daily cron jobs at 4:40 every day:
51 12 * * * /usr/bin/xmms /usr/music/Answers.mp3 1> /dev/null
I had it at 51 12 just because I been testing it, do I have to restart X or anything, or is that just wrong?
 
Old 02-24-2004, 11:58 PM   #8
Demonbane
LQ Guru
 
Registered: Aug 2003
Location: Sydney, Australia
Distribution: Gentoo
Posts: 1,796

Rep: Reputation: 47
check the logs
/var/log/cron
 
Old 02-25-2004, 12:02 AM   #9
ex0r
Member
 
Registered: Jun 2003
Posts: 36

Original Poster
Rep: Reputation: 15
Theres nothing in that log. Is this crontab like a dummy one? Would I have to create an entire new one? .... like when I do crontab -e I get

Code:
# If you don't want the output of a cron job mailed to you, you have to direct
# any output to /dev/null.  We'll do this here since these jobs should run
# properly on a newly installed system, but if they don't the average newbie
# might get quite perplexed about getting strange mail every 5 minutes. :^)
#
# Run the hourly, daily, weekly, and monthly cron jobs.
# Jobs that need different timing may be entered into the crontab as before,
# but most really don't need greater granularity than this.  If the exact
# times of the hourly, daily, weekly, and monthly cron jobs do not suit your
# needs, feel free to adjust them.
#
# Run hourly cron jobs at 47 minutes after the hour:
47 * * * * /usr/bin/run-parts /etc/cron.hourly 1> /dev/null
#
# Run daily cron jobs at 4:40 every day:
56 12 * * * /usr/bin/xmms /usr/music/Answers.mp3 1> /dev/null
#
# Run weekly cron jobs at 4:30 on the first day of the week:
30 4 * * 0 /usr/bin/run-parts /etc/cron.weekly 1> /dev/null
#
# Run monthly cron jobs at 4:20 on the first day of the month:
20 4 1 * * /usr/bin/run-parts /etc/cron.monthly 1> /dev/null
Is that right? or am I being stupid? Thank you for your help so far. I don't want to have to reboot to windows just for an alarm.
 
Old 02-25-2004, 12:26 AM   #10
Demonbane
LQ Guru
 
Registered: Aug 2003
Location: Sydney, Australia
Distribution: Gentoo
Posts: 1,796

Rep: Reputation: 47
Try doing it as an user, and remove 1> /dev/null so you get to see the output.
 
Old 02-25-2004, 06:09 PM   #11
ex0r
Member
 
Registered: Jun 2003
Posts: 36

Original Poster
Rep: Reputation: 15
I don't get it, not even $at is working for me....

Well I just tried executing just the program XMMS and it sent mail saying
CRITICAL : Unable to open display

I'm still not sure how to get cron to work but thank you Demon for all your help.
 
Old 02-25-2004, 06:16 PM   #12
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally posted by ex0r
I don't get it, not even $at is working for me....

Well I just tried executing just the program XMMS and it sent mail saying
CRITICAL : Unable to open display

I'm still not sure how to get cron to work but thank you Demon for all your help.
Thats most likely your problem, XMMS is a GUI application. Are you running the cron as the user who's started X? Or are you running the cron as maybe root logged in as another user in X? More details? Can you run the program using a CLI mp3 player with any problems?
 
Old 02-25-2004, 06:17 PM   #13
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
You shouldn't try to run a X program from cron,
really ... use mymp3 or mpg321 or something...
Firing up something in X makes it unnecessarily
complicated...


Cheers,
Tink
 
Old 02-25-2004, 06:19 PM   #14
ex0r
Member
 
Registered: Jun 2003
Posts: 36

Original Poster
Rep: Reputation: 15
Well yeah, I'm logged into root, I really don't use users... nor do I really know how to make any or do it, like I said I've been using linux for not long, is it not good to be logged into root? Do you think thats my problem?
 
Old 02-25-2004, 06:23 PM   #15
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
It's certainly not recommended to be
logged in as root all the time. One reason
is security, the other is safety :} ... as root
you can do SO much damage to your system.

The problem you're running into is that
cron or at are running as daemons in the
background. They don't know diddly-squat
about X ... and the shell they're running on
doesn't have a DISPLAY environment variable
set ...

My recommendation really would be to
a) create a user account for everyday use
and
b) use a command-line player for the alarm ;)


Cheers,
Tink
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
System clock correct, hardware clock wrong karlovac Linux - General 5 01-16-2009 07:19 PM
Simple Alarm Clock dudeman41465 Linux - Software 11 10-06-2006 11:33 PM
Exit status - Alarm clock?!?!?! edhellaby Mandriva 0 10-29-2005 11:40 AM
linux alarm clock? DJOtaku Linux - General 1 02-16-2005 01:41 AM
Linux Alarm Clock?? Scruff Linux - General 3 09-02-2003 09:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration