4

I am using ruby script to download bitcoin bootstrap.dat file, This file can only be downloaded by using torrent client so to download on command line i am using following ruby demo script:

#!/usr/bin/ruby env
`transmission-cli https://bitcoin.org/bin/blockchain/bootstrap.dat.torrent`

Now i run that script

root@master:~# ruby demo

But that script hangs because above transmission downloads torrents file perfectly but after that it start to seeding and uploading and never terminate automatically, Is there any way i can terminate this using my script?

Is there any way by which i can send kill or termination signal after torrent download finished?

Pradeep Gupta
  • 397
  • 1
  • 5
  • 17

1 Answers1

4

You can use the -f, -finish <script> which executes a script when the download is completed:

tmpfile=$(mktemp)
chmod a+x $tmpfile
echo "killall transmission-cli" > $tmpfile
transmission-cli -f $tmpfile your.torrent

You could also use rtorrent which has more options.

enrico.bacis
  • 30,497
  • 10
  • 86
  • 115
  • I got error executing script "killall transmission-cli": No such file or directory, Can you provide correct way here? – Pradeep Gupta Aug 20 '14 at 10:10
  • In case you want to run more downloads, it may make sense to use the PID instead, something like: `killfile=$(mktemp); transmission-cli -f "$killfile" -ep -u 64 -p $(python -c 'import random; print(random.randint(1024,65535))') "$i" & echo 'kill '$(jobs -p | tail -1)'; rm -f "$0"' > "$killfile"; chmod +x "$killfile"` – Tiana Aug 07 '19 at 10:49