bashshellaria2

Download multiple files with aria2c in parallel


I want to download multiple torrent files in parallel with aria2c with following codes:

me@host:~/Downloads$ find . -iregex ".*.torrent"  | while read line; do nohup aria2c "$line" &; done
bash: syntax error near unexpected token `;'

To solve the problem with subshells

me@host:~/Downloads$ find . -iregex ".*.torrent"  | while read line; do (nohup aria2c "$line" &); done
nohup: nohup: appending output to 'nohup.out'
appending output to 'nohup.out'
nohup: appending output to 'nohup.out'
nohup: appending output to 'nohup.out'
nohup: appending output to 'nohup.out'
nohup: appending output to 'nohup.out'
nohup: appending output to 'nohup.out'
nohup: appending output to 'nohup.out'
nohup: appending output to 'nohup.out'
nohup: appending output to 'nohup.out'
nohup: appending output to 'nohup.out'

But all the processes are in the stop process

me@host:~/Downloads$ ps -aux | grep 'aria'| sed "s/$USER/me/g"
me    5807  0.1  0.4  86208 18392 pts/0    S    22:58   0:00 aria2c ./ebd9863a73a5ef22344550a650d169a1.torrent
me    5809  0.0  0.4  85804 17884 pts/0    S    22:58   0:00 aria2c ./53ef22110569d46b445a1e908a7ae88f.torrent
me    5811  0.1  0.4  87336 19408 pts/0    S    22:58   0:00 aria2c ./a51accbbf14c8a05cb82caa7d8bec0c6.torrent
me    5813  0.0  0.4  84260 16528 pts/0    S    22:58   0:00 aria2c ./0eae6a261a340b8af159c0155aa8fab6.torrent
me    5815  0.0  0.3  82972 14400 pts/0    S    22:58   0:00 aria2c ./bf93f4618ba007ff95113156c802812b.torrent
me    5817  0.0  0.4  84256 16376 pts/0    S    22:58   0:00 aria2c ./f5938dd24367ffaf766ef99928660786.torrent
me    5819  0.0  0.4  86132 18440 pts/0    S    22:58   0:00 aria2c ./61ee21f83a33b91674926daf70c34947.torrent
me    5821  0.0  0.4  84100 16296 pts/0    S    22:58   0:00 aria2c ./710fc8dc201568d807aa7709b8fa072a.torrent
me    5823  0.0  0.3  82972 14364 pts/0    S    22:58   0:00 aria2c ./2b9cc942c04a8063bd8d4d8fd98814d9.torrent
me    5825  0.0  0.4  85832 18340 pts/0    S    22:58   0:00 aria2c ./8ffc0566591e1258c151d4d28843c55b.torrent
me    5827  0.0  0.3  82972 15208 pts/0    S    22:58   0:00 aria2c ./d9e39bfe0a907ffb580a975d8c8719d2.torrent
me    5829  0.0  0.3  83692 15616 pts/0    S    22:58   0:00 aria2c ./EDBDB765D87586FDA75C4287A1E9EA1E.torrent
me    5933  0.0  0.0  11928   956 pts/0    S+   23:04   0:00 grep --color=auto aria

How could git it done?


Solution

  • I don't know aria2c, but a simple way to do things in parallel, is often to use GNU Parallel

    find . -iregex ".*.torrent" -print0 | parallel -0 aria2c
    

    This will run, in parallel, one aria2c for each core your CPU has until all files are downloaded. If, for some reason, you specifically want to run, say 32, at a time, use:

    find ... | parallel -0 -j32 ...
    

    If you want a progress meter, use:

    find ... | parallel -0 --eta ...
    

    More examples and ideas here.