LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-11-2008, 03:44 PM   #1
Rotwang
Member
 
Registered: Jan 2004
Distribution: CentOS
Posts: 281

Rep: Reputation: 30
A shell script that will wget for 30 minutes, then stop?


There's this live comedy show every weeknight on the web. It streams out via a neverending flv file.

But the show is on kind of late at night (I'm on the east coast, it's on west coast), so what I want to do is essentially tape it.

If I wget the flv url, I can save the flv locally as a file and view it later. But if I start the wget and then go to sleep, it'll be recording all night long and the file will be like 4 gigs, and only 200 mb of it is actually the show.

So what I want to do is:

1. Start the wget at a certain time. (maybe via a cron)
2. End (kill) the wget process at a certain time (via another cron I guess).

It would be even cooler if I could just do this all without crons in a line command like "recordshow.sh <url> <starttime> <endtime> &", and it would just kill the wget and die at the endtime.

Any suggestions on how this could be done? I'm not good with shell scripting but very good with perl or php. thanks
 
Old 06-11-2008, 04:02 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Linux Mint 17, Debian 8
Posts: 7,865

Rep: Reputation: 311Reputation: 311Reputation: 311Reputation: 311
You could create a 200 mb partition and have wget download to that partition. When you run out of space in that partition wget will fail for lack of disk space. wget is set up to be able to resume a partial download where it left off so I suspect that the partial file left after a wget failure should be readable.

--------------------
Steve Stites
 
Old 06-11-2008, 04:07 PM   #3
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Hi.

You could use a sleep:
Code:
wget <url> &
WGETPID=$!
sleep <number of seconds to record for>
kill $WGETPID
Or you could use cron and have two scripts, one to start it:
Code:
nohup wget <url> &
echo $! > /tmp/recording-pid
and one to stop it:
Code:
if ps -ef | grep `cat /tmp/recording-pid` | grep wget | grep -v grep
    then
    kill `cat /tmp/recording-pid`
    rm -f /tmp/recording-pid
fi
Dave

Last edited by ilikejam; 06-11-2008 at 04:12 PM.
 
Old 06-11-2008, 04:10 PM   #4
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 44
cron is your friend


a cron job to start it at a certain time and a cron job to end it at a certain time. If it's a weekly show you can set it to record the same night every week at the same time. just search for cron or crontab or cron jobs and you'll find a ton of info.
 
Old 06-11-2008, 06:03 PM   #5
Rotwang
Member
 
Registered: Jan 2004
Distribution: CentOS
Posts: 281

Original Poster
Rep: Reputation: 30
Yea I know how to do crons, the difficult part was how capture the pid and use it later to kill the process. Looks like ilikejam has the answer. Wish I could do it from command line without crons...
 
Old 06-11-2008, 06:35 PM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
The first example would work from the console. You could create a script (in ~/bin/ for example) so that you could launch the commands easily.

Maybe putting the length in minutes at the top of the script and letting bash calculate the seconds would be easier to maintain.

Code:
LENGTH=<length of program in minutes>
wget <url> &
WGETPID=$!
sleep $((LENGTH*60))
kill $WGETPID
The "$!" variable expands to the last background job so you don't have to use a cron job. Search for JOBSPEC in the bash info manual for more info.

Creating very short scripts in ~/bin/ to free you of having to remember the options and option arguments is a common practice that can simplify many tasks.

Last edited by jschiwal; 06-11-2008 at 06:37 PM.
 
Old 06-11-2008, 06:50 PM   #7
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
You could use the 'at' demon to run the 'sleep' type script, e.g. if you saved the script as '/export/home/user/record':

$ echo /export/home/user/record | at 05:00

which would run the script at 05:00

Dave
 
Old 06-12-2008, 02:28 AM   #8
lurko
Member
 
Registered: Jun 2006
Location: Ontario, Canada
Distribution: Debian
Posts: 448

Rep: Reputation: 35
You can use pkill to kill(or send other signals to) a process "based on name and other attributes". You can use pgrep to find the PID of a process instead of killing it.

So if you launched wget with wget http://anysite.com you should be able to kill it with pkill -f "anysite.com".
 
  


Reply


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to stop a process running in background (on a shell script) Azk00 Linux - Newbie 3 02-01-2008 04:24 AM
How to stop java deamon in clustered environment through shell script rakeshnair83 Linux - Software 0 12-18-2007 05:59 AM
ftp transfert stop after 45 minutes numero7 Linux - Software 0 09-14-2007 06:56 AM
a script that runs wget every 3 minutes Menestrel Programming 3 07-26-2005 11:22 AM
GNU wget return codes for shell script greenhornet Programming 3 05-09-2004 07:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:30 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration