[opensuse] wget and pid
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. Any help would be appreciated. Thanks, Istvan -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
* 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` -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Registered Linux User #207535 @ http://linuxcounter.net Photos: http://wahoo.no-ip.org/piwigo -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Sun, 2017-05-14 at 16:27 -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`
I did not know of "pidof" command. Useful to know. Regards. Sudhir
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 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Sun, 14 May 2017 22:47:09 +0200 Istvan Gabor <suseuser04@gmail.hu> 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
Typing 'wget pid' into google shows various possibilities. Why don't you try some and let us know how they work? I could write a perl script but (a) it may not be necessary and (b) why should I? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
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. hth & regards, Carl -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 2017-05-15 02:30, Carl Hartung wrote:
On Sun, 14 May 2017 22:47:09 +0200 Istvan Gabor wrote:
...
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< - - - - -
The important thing to know is that in a bash script, $! contains the PID of the previous backgrounded program. $? should contain the PID of the previous command, and $$ the one of the shell or script. With that info it is easy to write a script with wget instead :-) -- Cheers / Saludos, Carlos E. R. (from 42.2 x86_64 "Malachite" (Minas Tirith))
On Mon, 15 May 2017 02:57:20 +0200 Carlos E. R. wrote:
The important thing to know is that in a bash script, $! contains the PID of the previous backgrounded program. $? should contain the PID of the previous command, and $$ the one of the shell or script.
With that info it is easy to write a script with wget instead :-)
Thanks for crossing my T's and dotting my I's Carlos! :) 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. I know it can be used to fetch media files, but I'd be very surprised to learn that it can now also decode and dump streams :) hence my quick example showing one of many possible alternate solutions. regards, Carl -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 2017-05-15 04:03, Carl Hartung wrote:
On Mon, 15 May 2017 02:57:20 +0200 Carlos E. R. wrote:
The important thing to know is that in a bash script, $! contains the PID of the previous backgrounded program. $? should contain the PID of the previous command, and $$ the one of the shell or script.
With that info it is easy to write a script with wget instead :-)
Thanks for crossing my T's and dotting my I's Carlos! :)
Ah, you gave me the needed clue for finding the rest of the info. :-) Previous to your post I had no idea how to do it. When I saw that I remembered that I wrote a note about it!
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. I know it can be used to fetch media files, but I'd be very surprised to learn that it can now also decode and dump streams :) hence my quick example showing one of many possible alternate solutions.
Yep! :-) I'm now thinking of tools like "youtube-dl" that will download a youtube (or some other sources) video or audio and store it correctly. The tool parses the page to find out the link that would have to be given to wget to download it. Another tool for downloading streams is "streamripper", specially for radio stations on internet. This one has CLI options for automatically stopping after so many seconds. -- Cheers / Saludos, Carlos E. R. (from 42.2 x86_64 "Malachite" (Minas Tirith))
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
On 05/14/2017 09:28 PM, Istvan Gabor wrote:
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.
Any help would be appreciated.
Thanks,
Istvan
I don't think it's possible to use $! to get the background pid, because the background process is the child process of wget, and $! returns the pid of the shell's child. I'd go with extracting the pid from wget's output: #!/bin/bash error () { echo "$0: error: $@" 2>&1; exit 1; } wout="$( wget -b -q -O output-file url-address )" \ || error "wget failed (when starting in background)" printf "%s\n" "$wout" # extract pid. pid="$( sed -n '/Continuing in background, pid / { s/^.*pid //; # strip all up to "pid" s/\.$//; # strip trailinf dot p; # print line q # quit }' <<<"$wout" \ | grep . # failure when nothing is left from the above )" \ || error "extracting pid from wget output failed" printf "wget's backgroung pid: %d\n" "$pid" exit $? Have fun, Berny -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
participants (7)
-
Bernhard Voelker
-
Carl Hartung
-
Carlos E. R.
-
Dave Howorth
-
Istvan Gabor
-
Patrick Shanahan
-
Sudhir Anand