Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing multiple instances of script - GNU Parallel

I am currently attempting to use GNU Parallel, however I am not being successful at it. Installation was pretty easy. My goal is to run two parallel instances of python script youtube-dl with its corresponding arguments. What would be the proper way to execute the script using parallel?

Parallel

parallel 'youtube-dl -w --no-warnings -o "/media/video1.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/stun-gun-used-on-man-in-police-custody-dies-lawsuit-dnt-brown-tsr.cnn"' 'youtube-dl -w --no-warnings -o "/media/video2.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/5-year-old-saves-family-from-house-fire.ktla"'

It works if run the command seperately without parallel:

youtube-dl -w --no-warnings -o "/media/video1.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/stun-gun-used-on-man-in-police-custody-dies-lawsuit-dnt-brown-tsr.cnn"

youtube-dl -w --no-warnings -o "/media/video2.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/5-year-old-saves-family-from-house-fire.ktla"
like image 669
MaryCoding Avatar asked Apr 09 '26 20:04

MaryCoding


1 Answers

For just two streams, it would be easier just to put an ampersand (&) at the end of the first command and you are all done. Like this:

youtube-dl -w --no-warnings -o "/media/video1.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/stun-gun-used-on-man-in-police-custody-dies-lawsuit-dnt-brown-tsr.cnn" &
youtube-dl -w --no-warnings -o "/media/video2.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/5-year-old-saves-family-from-house-fire.ktla" &

# Wait for both downloads to finish
wait

If you want to use GNU Parallel... something like this - though I normally get told a better way.... :-)

Create a file called work.txt that contains this:

/media/video1.%(ext)s http://www.cnn.com/videos/us/2015/11/11/stun-gun-used-on-man-in-police-custody-dies-lawsuit-dnt-brown-tsr.cnn
/media/video2.%(ext)s http://www.cnn.com/videos/us/2015/11/11/5-year-old-saves-family-from-house-fire.ktla

Then the command would be:

parallel --colsep " " youtube-dl -w --no-warnings -o {1} {2} < work.txt

Another option would be to simply put your two commands in a file and send that to GNU Parallel's standard input like this:

Store this in work.txt

youtube-dl -w --no-warnings -o "/media/video1.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/stun-gun-used-on-man-in-police-custody-dies-lawsuit-dnt-brown-tsr.cnn"
youtube-dl -w --no-warnings -o "/media/video2.%(ext)s" "http://www.cnn.com/videos/us/2015/11/11/5-year-old-saves-family-from-house-fire.ktla"

then just run

parallel < work.txt
like image 127
Mark Setchell Avatar answered Apr 12 '26 09:04

Mark Setchell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!