3

我想使用以下代码与 aria2c 并行下载多个 torrent 文件:

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

解决子shell的问题

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'

但是所有进程都在停止进程中

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

怎么能把它搞定?

4

2 回答 2

3

我不知道aria2c,但并行做事的简单方法通常是使用GNU Parallel

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

这将为您的 CPU 拥有的每个内核并行运行一个aria2c,直到下载所有文件。如果出于某种原因,您特别想一次运行 32 次,请使用:

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

如果您想要进度表,请使用:

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

更多示例和想法在这里

于 2019-02-24T15:36:01.347 回答
1

您想aria2c一次下载多个 torrent 文件,还是想专门使用您发布的命令来下载?如果首先,那么以下简单命令会执行此操作:

aria2c *torrent

获取当前目录中的所有 torrent 文件并并行下载它们。

于 2020-09-20T07:32:41.400 回答