A shell script that will wget for 30 minutes, then stop?
Linux - GeneralThis 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
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.
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
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.
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.
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...
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.
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".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.