Automating Bit-torrent Downloads
Driven by the need for accessibility and more storage space, many home computer users are now incorporating file servers and NFS systems into their home computing environment. Using a Linux based NFS system or File Server (Ubuntu Server Edition for example) allows for a huge range of personalisation and customisation options. One of these is the ability to automate the downloading of bit-torrent files, with a very low overhead, into a shared directory, and spreading the bandwidth load throughout the day. The following tutorial will use Ubuntu Server Edition 9.04 as the example although the applications and configuration options are uniform across Linux distributions.
To begin we will create a new directory for the bit-torrent files. You can create this in your home directory or in whatever shared directory you’d like to use on your NFS or File Server. To create the directory execute the following command:
mkdir -p ~/torrents
If you don’t want the “torrents” directory under your home directory then substitute the tilde for the desired path.
Next, we will create another directory to contain the bash scripts that we will use to assist with automating the downloading process. To do this execute the following command:
mkdir -p ~/bash_scripts
Remember to substitute the tilde to reflect the desired path.
Now that the directories have been created we can get to work writing the simple bash scripts that will assist us with automating the downloading of bit-torrent files. The first bash script we will create1 will execute the bittorrent application, scan the appropriate directory for bit-torrent files, and start downloading any found bit-torrent files or terminate if none are found. To create the bash script execute the following command if you are using a Graphical User Interface (GUI):
gedit ~/bash_scripts/bittorrentstart.sh
or the following if you are at the terminal:
nano ~/bash_scripts/bittorrentstart.sh
When the editor opens paste in the following text (or download bittorrentstart.sh here):
#!/bin/sh
# Start Downloading Torrent Files
# Written by Simon Ives – http://www.simonives.info
#
echo “Starting the Download Torrents Script”
#
echo “Checking for Torrent files”
#
if [ -f ~/torrents/*.torrent ]; then
echo “Executing Bittorrent Application and saving progress to torrent.log”
nohup btlaunchmany ~/torrents > ~/torrents/torrent.log &
else echo “No Torrent files found”
fi
Remember to substitute the tilde to reflect the desired path and to save the file before exiting.
The next bash script that we will create is to terminate the bittorrent application. If you are using a Graphical User Interface (GUI) then execute:
gedit ~/bash_scripts/bittorrentstop.sh
or the following if you are at the terminal:
nano ~/bash_scripts/bittorrentstop.sh
When the editor opens paste in the following text (or download bittorrentstop.sh here):
#!/bin/bash
# Stop Downloading ALL Torrent Files
# Written by Simon Ives – http://www.simonives.info
#
echo “Stopping all bittorrent downloads”
killall btlaunchmany
Remember to save the file before exiting.
Now that the two bash scripts have been created we need to define them as being executable. To do this execute the following two commands (one at a time), remembering to substitute the tilde for any path variations you’ve made:
chmod +x ~/bash_scripts/bittorrentstart.sh
chmod +x ~/bash_scripts/bittorrentstop.sh
And that’s the bash scripts finished. If you have a look at the contents of the first bash script we created, bittorrentstart.sh, you’ll see that it scans the “torrents” directory we created earlier for bit-torrent files (files ending with .torrent). All you need for your bit-torrent files to download when this script is executed is for the bit-torrent files to be within the “torrents” directory. The bittorrent application will create a new sub-directory for each bit-torrent file that it downloads.
The next part of automating bit-torrent downloads is to edit the system’s cron file. Cron is an application the tells your Linux based computer when to perform certain tasks. We are going to edit your cron file to have your computer execute the first bash script we created, bittorrentstart.sh, at an appropriate time, and then execute the second bash script we created, bittorrentstop.sh, at an appropriate time. The effects of this will be that your bit-torrent files will automatically begin downloading when you want them to, and they will automatically stop downloading when you want them to.
My home computers are most heavily used between the hours of 6am and 10pm. I don’t want the extra bandwidth consumption of bit-torrent file downloads during these hours so I’ve set-up my cron file to execute the bittorrentstart.sh bash script after 10pm and to execute the bittorrentstop.sh script before 6am. You can alter these times to suit your individual needs.
What we will do is create a file called cron.txt in our home directory that we will use to to easily edit our cron details. To do this execute the following command if you are using a Graphical User Interface (GUI):
gedit ~/cron.txt
or the following if you are at the terminal:
nano ~/cron.txt
You’ll be presented with a blank text document that we need to edit with the times that we want our scripts to be executed and their location. My cron.txt file appears as follows:
# Start BitTorrent Download Script
05 22 * * * sh ~/bash_scripts/bittorrentstart.sh
# Stop ALL BitTorrent Downloads Script
55 05 * * * sh ~/bash_scripts/bittorrentstop.sh
Remember to substitute the tilde to reflect the desired path and to save the file before exiting.
I’ll break down the first entry which will also explain the second.
The first line is a comment. It lets you know what is being done.
The second line is the cron entry itself. 05 is the minutes, 22 is the hour, and the other three asterisks are wild-cards that are in place of the day, month, and year columns. The remainder, beginning from sh, tells cron to execute the bash script. This entry will execute the bash script bittorrentstart.sh at 10:05 PM on every day, of every month, of every year. Cron entries are in 24 hour time so if you want a particular line to begin at 8:15 PM, for example, then the time columns would read – 15 20 * * *.
We need to load this file into cron and to do this we enter the following in the terminal:
crontab ~/cron.txt
Remember to substitute the tilde to reflect the desired path.
If you want to check that your cron file has been successfully updated then execute the following command:
crontab -l
And that’s it. Now, at 10:05 PM every day any bit-torrent files in the “torrents” directory will automatically download. Should this process not be complete by 5:55 AM all torrent downloads will be terminated, freeing system resources and bandwidth for your daily computing needs.
Another handy feature is that this process creates a file called torrent.log in the “torrents” directory. You can open this file with your favourite text editor and it will present a live update on the status of your bit-torrent downloads.
Notes
1. Always be careful when using bash scripts found on the internet. Malicious developers can create bash scripts that may be potentially harmful to your computer.













Hello
I loose control!
Best deposit bonus online casino. Betting online casino free Best deposit bonus online casino. Betting online casino EURO Jackpot No deposit required online casino bonus. List of online casino Play No deposit required online casino bonus. List of online casino UK Jackpot No deposit bonuses from online casino. Casino guide free No deposit bonuses from online casino. Casino guide EURO poker No deposit casino. No deposit bonuses from online casino games No deposit casino. No deposit bonuses from online casino EURO Jackpot No deposit casino. No deposit required online casino bonus games No deposit casino. No deposit required online casino bonus EURO blackjack Be happy