LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-18-2010, 09:18 AM   #1
thiemster
LQ Newbie
 
Registered: Jan 2010
Location: Ohio, USA
Distribution: Arch Linux w/ Gnome, Ubuntu 9.10, Windows Vista
Posts: 24

Rep: Reputation: 15
How to run a program for a specific amount of time starting at a specific time?


I want to record an internet radio station starting at 2:00am tomorrow morning. The specific program on the radio station lasts until 6:00am.

The command I need to run to record the station is:
Code:
mplayer http://wjcu.jcu.edu:8001/listen.pls -ao pcm:file=indie_heat_of_the_night.wav -vc dummy -vo null
I'd use cron, but 1. I'm not sure how to and 2. it seems unnecessarily complicated for something that I only want to run once. If cron is the only/easiest solution, I guess I'll just have to resort to that, but I'd rather not.

Thanks in advance for any answers.
 
Old 05-18-2010, 09:23 AM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,650

Rep: Reputation: 525Reputation: 525Reputation: 525Reputation: 525Reputation: 525Reputation: 525
well, "at" is good for starting oneoffs. Then you can "at" a "killall mplayer" or similar for 6AM.
 
1 members found this post helpful.
Old 05-18-2010, 09:27 AM   #3
thiemster
LQ Newbie
 
Registered: Jan 2010
Location: Ohio, USA
Distribution: Arch Linux w/ Gnome, Ubuntu 9.10, Windows Vista
Posts: 24

Original Poster
Rep: Reputation: 15
I was actually thinking of doing that but there's one problem: I tried to run the command using "at" last night, but it never ran. A few minutes ago, I tried running a simple "echo hello world" with "at". It was supposed to run it 5 minutes from when I set it, but it never did, but rather just removed "echo hello world" from the queue list at the specified time without running the command. Do you know what could be wrong? There weren't any error messages or any indication of what could have gone wrong...
 
Old 05-18-2010, 09:33 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
If you run a script from some kind of startup script, or a background function such as "at" or "cron", I think you would need to specify where its output would go.

In the case of your example, maybe just do this:

echo "hello world" > demofile

Then just check and see that demofile got created and has "hello world" in it.
 
Old 05-18-2010, 09:36 AM   #5
thiemster
LQ Newbie
 
Registered: Jan 2010
Location: Ohio, USA
Distribution: Arch Linux w/ Gnome, Ubuntu 9.10, Windows Vista
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pixellany View Post
If you run a script from some kind of startup script, or a background function such as "at" or "cron", I think you would need to specify where its output would go.

In the case of your example, maybe just do this:

echo "hello world" > demofile

Then just check and see that demofile got created and has "hello world" in it.
How would I be able to run the original command with this though? (as it does not need any output file, or at least I don't think it does...)
 
Old 05-18-2010, 09:38 AM   #6
thiemster
LQ Newbie
 
Registered: Jan 2010
Location: Ohio, USA
Distribution: Arch Linux w/ Gnome, Ubuntu 9.10, Windows Vista
Posts: 24

Original Poster
Rep: Reputation: 15
Thanks pixellany. It worked. But how would I use this to run the "mplayer...." command?
 
Old 05-18-2010, 09:42 AM   #7
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,043

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
Quote:
Originally Posted by thiemster View Post
I was actually thinking of doing that but there's one problem: I tried to run the command using "at" last night, but it never ran. A few minutes ago, I tried running a simple "echo hello world" with "at". It was supposed to run it 5 minutes from when I set it, but it never did, but rather just removed "echo hello world" from the queue list at the specified time without running the command. Do you know what could be wrong? There weren't any error messages or any indication of what could have gone wrong...
The simple question first: is the atd daemon running at all? If it's not then at will not work.

The second thing now: commands programmed to be run using at are not attached to any particular terminal device, which means that using "echo" to test "at" will not bring you any good result at all.

As a test you could rather do this:

Code:
echo foo > /tmp/testfile.txt | at -m HH:MM
Just set "HH:MM" to the next minute to test.
 
Old 05-18-2010, 09:45 AM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,043

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
About how to stop the thing, you could very well do what they've told you above, and use killall. If you need more control you could just fit all the pieces together in a single script, then launch it using at, then just forget about it. Something like this:

Code:
#!/bin/bash

mytask & # tune this
PID_mytask=$!
sleep 6h # sleeps 6 hours, tune this
kill -9 $PID_mytask
 
1 members found this post helpful.
Old 05-18-2010, 09:46 AM   #9
thiemster
LQ Newbie
 
Registered: Jan 2010
Location: Ohio, USA
Distribution: Arch Linux w/ Gnome, Ubuntu 9.10, Windows Vista
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by i92guboj View Post
The simple question first: is the atd daemon running at all? If it's not then at will not work.
Yes, the atd daemon is running.

Quote:
Originally Posted by i92guboj View Post
The second thing now: commands programmed to be run using at are not attached to any particular terminal device, which means that using "echo" to test "at" will not bring you any good result at all.

As a test you could rather do this:

Code:
echo foo > /tmp/testfile.txt | at -m HH:MM
Just set "HH:MM" to the next minute to test.
that does work with echo, but how would I fit that to allow mplayer to run? I tried "mplayer ....blah...blah...blah > test.txt" but it did not successfully record. Instead, it immediately exited.
 
Old 05-18-2010, 09:52 AM   #10
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,043

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
Quote:
Originally Posted by thiemster View Post
Yes, the atd daemon is running.



that does work with echo, but how would I fit that to allow mplayer to run? I tried "mplayer ....blah...blah...blah > test.txt" but it did not successfully record. Instead, it immediately exited.
That's just a test, and it will not work with mplayer (at most, it would save the text output from mplayer to a plain text file which is not what you want).

The first thing you need to do is to make sure that your mplayer command works when ran directly from the command line.

Once you've done that, integrate that command in the script I wrote above, and run it using at -f
 
Old 05-18-2010, 09:57 AM   #11
thiemster
LQ Newbie
 
Registered: Jan 2010
Location: Ohio, USA
Distribution: Arch Linux w/ Gnome, Ubuntu 9.10, Windows Vista
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by i92guboj View Post
That's just a test, and it will not work with mplayer (at most, it would save the text output from mplayer to a plain text file which is not what you want).

The first thing you need to do is to make sure that your mplayer command works when ran directly from the command line.

Once you've done that, integrate that command in the script I wrote above, and run it using at -f
Thanks. The mplayer command does work (I've used it before), so I'll try to fit it into the script and hopefully it'll work this time.
 
Old 05-18-2010, 10:03 AM   #12
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,043

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
It should, just make sure you use '&' after the command, so it starts into the background and the $PID can be captured. Then just launch your script using at -f myscript.sh -m HH:MM. Remember that more than probably you won't see a thing on your screen, since as I said the processes ran this way are not attached to any particular console.
 
1 members found this post helpful.
Old 05-18-2010, 10:04 AM   #13
thiemster
LQ Newbie
 
Registered: Jan 2010
Location: Ohio, USA
Distribution: Arch Linux w/ Gnome, Ubuntu 9.10, Windows Vista
Posts: 24

Original Poster
Rep: Reputation: 15
Thank you very much everyone who offered solutions (and especially i92guboj). I tried the script with "sleep 3m" and it recorded the radio station for 3 minutes and 6 seconds and then stopped. The 6 seconds are unimportant, so I consider this a complete success!

If anyone is curious, my final script to record for 4 hours is:
Code:
#!/bin/bash

mplayer http://wjcu.jcu.edu:8001/listen.pls -ao pcm:file=indie_heat_of_the_night.wav -vc dummy -vo null &
PID_mytask=$!
sleep 4h
kill -9 $PID_mytask
and my "at" command is:
Code:
at -f record_radio.sh 2:00am tomorrow
 
  


Reply

Tags
at, batch, cron, date, scheduling, time


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
IsThere a fridge, that we can program at specific date/time to unfreeze specific food frenchn00b General 3 07-22-2009 12:26 AM
using pkill to kill a specific program after a certain time - help bcameron Linux - Newbie 3 12-07-2008 03:55 PM
run program automatically at specific time simon_qwl Programming 2 03-20-2005 11:58 AM
Running a program for a specific period of time CaptainHowdy Linux - Software 2 08-22-2004 08:02 PM
Only starting command in a specific time period jeroenvrp Linux - Software 3 07-21-2004 12:18 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration