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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-18-2010, 08:18 AM
|
#1
|
|
LQ Newbie
Registered: Jan 2010
Location: Ohio, USA
Distribution: Arch Linux w/ Gnome, Ubuntu 9.10, Windows Vista
Posts: 24
Rep:
|
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.
|
|
|
|
05-18-2010, 08:23 AM
|
#2
|
|
Senior Member
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,474
|
well, "at" is good for starting oneoffs. Then you can "at" a "killall mplayer" or similar for 6AM.
|
|
|
1 members found this post helpful.
|
05-18-2010, 08:27 AM
|
#3
|
|
LQ Newbie
Registered: Jan 2010
Location: Ohio, USA
Distribution: Arch Linux w/ Gnome, Ubuntu 9.10, Windows Vista
Posts: 24
Original Poster
Rep:
|
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...
|
|
|
|
05-18-2010, 08:33 AM
|
#4
|
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,797
|
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.
|
|
|
|
05-18-2010, 08:36 AM
|
#5
|
|
LQ Newbie
Registered: Jan 2010
Location: Ohio, USA
Distribution: Arch Linux w/ Gnome, Ubuntu 9.10, Windows Vista
Posts: 24
Original Poster
Rep:
|
Quote:
Originally Posted by pixellany
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...)
|
|
|
|
05-18-2010, 08:38 AM
|
#6
|
|
LQ Newbie
Registered: Jan 2010
Location: Ohio, USA
Distribution: Arch Linux w/ Gnome, Ubuntu 9.10, Windows Vista
Posts: 24
Original Poster
Rep:
|
Thanks pixellany. It worked. But how would I use this to run the "mplayer...." command?
|
|
|
|
05-18-2010, 08:42 AM
|
#7
|
|
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 3,965
|
Quote:
Originally Posted by thiemster
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.
|
|
|
|
05-18-2010, 08:45 AM
|
#8
|
|
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 3,965
|
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.
|
05-18-2010, 08:46 AM
|
#9
|
|
LQ Newbie
Registered: Jan 2010
Location: Ohio, USA
Distribution: Arch Linux w/ Gnome, Ubuntu 9.10, Windows Vista
Posts: 24
Original Poster
Rep:
|
Quote:
Originally Posted by i92guboj
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
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.
|
|
|
|
05-18-2010, 08:52 AM
|
#10
|
|
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 3,965
|
Quote:
Originally Posted by thiemster
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
|
|
|
|
05-18-2010, 08:57 AM
|
#11
|
|
LQ Newbie
Registered: Jan 2010
Location: Ohio, USA
Distribution: Arch Linux w/ Gnome, Ubuntu 9.10, Windows Vista
Posts: 24
Original Poster
Rep:
|
Quote:
Originally Posted by i92guboj
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.
|
|
|
|
05-18-2010, 09:03 AM
|
#12
|
|
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 3,965
|
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.
|
05-18-2010, 09:04 AM
|
#13
|
|
LQ Newbie
Registered: Jan 2010
Location: Ohio, USA
Distribution: Arch Linux w/ Gnome, Ubuntu 9.10, Windows Vista
Posts: 24
Original Poster
Rep:
|
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
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:35 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|