Synposis
This is a solution for torrent downloaders with btdownloadcurses and the machines has to be rebooted. The script saves all running downloads every X minutes to a file. After reboot you can easily start the torrent-downloads again.
Summery
Sometimes it happens that you must reboot a machines that is downloading torrents with the command line tool btdownloadcurses. Than there are tree options:
- You are in a hurry and you there is no time to register what torrents are downloading now. First things First! And that is reboot the machine.
- The reboot in no hurry job so you have time to register the downloading torrents with ps -aux | grep btdownloadcurses > Torrents-To-Do.txt or someting like that
- You forget all above and just reboot. Now you have to search the internet witch torrents you where downloading.
The program that you find here creates a file names "Torrents-To-Do.txt" and update that every 5 minutes (cronjob) so you always have a update file with running updates.
The script
~/torrents_to_do.sh
#!/bin/sh
# Version 2.0.2
#
# SYNOPSIS
# This script make a file named /extra/incoming/Torrents-To-Do.txt
# with the torrents that where runnen.
#
# PROGRAMMER
# By Rob Groen 2009-07-09
#
# DISCRIPTION#
# It can executed by hand or with a cronjob.
# The script checks if there are btdownloadcurses are running
# before rewriting the (torrents) Tottents-To-Do.txt file
#
#
# UPDATES
# 20090816 - 2.0.2
# Quoted the torrent file name so that filenames with
# special characters like "(" ")" don't give an
# error any more.
#
############################################################
# CONFIG
#
# Path to the directory where you want to store the file
# that holds the data of the running torrents.
# The filename is: Torrents-To-Do.txt
#
# /PATH/TO/YOUR/PREFERRED/DIRECTORY
# like: DIRECTORY="/home/john_doe/torrents"
DIRECTORY="/home/john_doe/torrents";
#
# END CONFIG
# Get the running torrents
OUTPUT="$(ps -ef | grep /usr/bin/btdownloadcurses | grep -v grep)";
# If there are torrents than write them to a file. This prevents
# overwriting the file without any data if there are no torrents running.
# Add the btdownloadcurses command so all lines in the file are ready to
# execute.
if [ "$OUTPUT" != '' ]; then
ps -ef | grep /usr/bin/btdownloadcurses | grep -v grep | awk -v dq='"' '{print "btdownloadcurses " dq$10dq}' > $DIRECTORY/Torrents-To-Do.txt
fiThe only thing you have to do is config the path to your directory. That's the line
DIRECTORY="/home/john_doe/torrents";You can execute the scrip with the command:
sh ~/torrents_to_do.shOPTIONAL: Of course you can make the script executable so you can start is without the sh command. use "chmod u+x ~/torrents_to_do.sh" to make script executable.
Now check is the file Torrents-To-Do.txt is created and check the line in that file. The lines must look like this:
btdownloadcurses "http://WWW.SOME-TORRENT-SITE.COM/1234567/MOVIE_01.wmv.4462707.TPB.torrent"
btdownloadcurses "http://WWW.SOME-TORRENT-SITE.COM/2345678/MOVIE_02.wmv.4411357.TPB.torrent"Cronjob
Now you have to make a cronjob that runs the scrip every 5 minutes (or whatever you like).
To edit or create a cronjob type:
crontab -eNow your in the crontab and you can edit it with your favorite editor.
Add this line:
5 * * * * sh /PATH/TO/torrents_to_do.shSave the crontab and your ready.
After a reboot you always have a file that contains the last running torrents.
I didn't make a solution to start the btdownloadscurses automatically because I always use screen on my machines and a simply copy the lines from the Torrents-To-Do.txt file one by one in each screen.
