On Sun, 14 May 2017 20:30:42 -0400, Carl Hartung wrote:
On Sun, 14 May 2017 22:47:09 +0200 Istvan Gabor wrote:
On Sun, 14 May 2017 16:27:31 -0400, Patrick Shanahan wrote:
* Istvan Gabor <suseuser04@gmail.hu> [05-14-17 15:32]:
Hello:
I would like to use cron to start and stop wget commands using wget -q (quiet) and -b (background) options. For stopping the correct wget connect at given time I need to know its pid. wget -bq url runs like this:
wget -b -q -O output-file url-address Continuing in background, pid 10874.
I should somehow record the pid in a file and use it with the kill command, but I don't know how I could do it.
simple if you have only one instance of wget or want to kill all instances: kill -9 `pidof wget`
Thanks Patrick.
I want to run several (at least 2) wgets parallel. If I had only one I could also use 'killall wget'.
I use wget to record live streams that is why I have to start and stop it at given times.
Istvan
Hi Istvan,
Here's a solution based upon mplayer with community 'one-click' installed codecs:
E.g. place 'streamcap.sh' in ~/bin - - - - - 8< - - - - - #!/bin/bash # Set 'sleep' value, below, to the length of the show plus # whatever leading / trailing times are needed to avoid # inadvertently 'clipping' the show at it's start or end. NOW=$(date +"%Y%m%d") mplayer -vc null -vo null {stream URI} -dumpstream -dumpfile ~/path/$NOW-Program-Name.mp3 & sleep 62m kill $! - - - - - 8< - - - - - Notes:
The 'mplayer ... &' command string is a single line.
The closing 'kill $1' terminates mplayer.
The above example is called by cron at one minute before show time and the 'sleep' value is set to {show duration} + 2 minutes to yield one minute 'leading' and 'trailing' times. These times can be shortened if your system clock is accurate and the stream times are consistently punctual.
Carl, Carlos, Bernhard: Thank your very much for your help. In the above example I like the idea to use sleep until the show ends. I'd have never figured this myself.
Istvan didn't describe the stream in detail, but as I presently understand it, when wget is used to retrieve a typical stream 'link,' it usually yields just a meta file which specifies the mime type and/or protocol along with the proper stream URI.
In this specific case wget interestingly downloads the live media stream aac file. The stream is from streamtheworld.com. mplayer also works with -dumpstream option. I also experimented with it in the meantime and found the following solution: startstream.sh: #! /bin/bash /usr/bin/wget -q -O <output-file> <stream-url> & pid=$! echo $pid > stream.pid exit In this case $! gives back the pid of the last backgrounded process, wget. Instead of using -b (background) option of wget I use & at the end of the command line. (If I use -b, $! will be empty and won't give back wget's pid.) stopstream.sh: #! /bin/bash pid=`cat stream.pid` kill $pid exit I use startstream.sh and stopstream.sh in crontab. Thank you again, Istvan -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org