Today i decided to write a script which would simplify the process of remotely initiating a torrent download on my dreambox. The script just cuts out the need to use telnet and the bash prompt. In the off chance that someone wants to do something similar, this is how i did it.
I'm using the PLI Iolite 2008 Edition image on my 7020 and couldn't find a torrent plugin, so i had to use ctorrent.
The script is launched via crond at midnight (to use up my off peak mbs) or any time via telnet. It checks if .torrent files exist in a specific folder on the HDD, then proceeds to download them according to the settings specified in the script. Hence, i FTP .torrent files to the dbox and the downloads start at midnight.
ctorrent is available (only for the 7020).
Either extract the contents of the 'ctorrent'.gz file to the /tmp directory, and then install via the 'software management/manual addons'
or
copy the .gz file to /tmp directory, then from telnet run
Here is my simple scriptCode:gunzip /tmp/ctorrent_1.3.4-r6_powerpc.ipk.gz ipkg install /tmp/ctorrent_1.3.4-r6_powerpc.ipk
Adjust the variables and save the script somewhere using a unix compatible editor, i call it dts.sh and keep it in /etcCode:#!/bin/sh stime=1 #Seed Time hrs port=1325 #Port +1 for each simultaneous download (ie 5000, 5001, 5002...5010...) cache=1 #MBs torrent cache URate=18 #In KB/S Set to 10% lower than max Up rate - Split evenly amongst multiple downloads DRate=999 #In KB/S Split evenly amongst multiple downloads - Set really high to max it MDownload=3 #Max Simultaneous downloads - any 'leftover' torrents will be kept and downloaded the next time TDir="/media/hdd/Torrents" #Where .Torrent files are uploaded/kept TDown="/media/hdd/Torrents/Downloads" #Download dir LDir="/media/hdd/Torrents/Logs" #Log dir DelTor=Yes # Yes or No - Delete .Torrent file after starting download Log=Yes # Yes or No - Logs output of ctorrent for each download to a file in log dir mkdir -p "$TDir" mkdir -p "$TDown" if [ $Log = Yes ] then mkdir -p "$LDir" time=`date -I` fi cd "$TDir" ls -1 *.torrent > tor1_temp if [ $? = 0 ] then TorData=`cat tor1_temp | tr '\n' '|'` lines=`wc -l tor1_temp| awk '{print $1}` rm tor1_temp if [ $MDownload -lt $lines ] then lines=$MDownload fi div=1 while [ $div -lt $lines ] do div=`expr $div + 1` done DRate=`expr $DRate / $div` URate=`expr $URate / $div` count=1 cd "$TDown" while [ $count -le $lines ] do Tor=`echo $TorData | cut -f$count -d"|"` if [ $Log = Yes ] then ctorrent -e $stime -C $cache -p $port -D $DRate -U $URate "$TDir/$Tor" > "$LDir/$time.$Tor".txt & else ctorrent -e $stime -C $cache -p $port -D $DRate -U $URate "$TDir/$Tor" > /dev/null & fi if [ $DelTor = Yes ] then rm "$TDir/$Tor" fi port=`expr $count + $port` count=`expr $count + 1` done else rm tor1_temp exit fi
The only way i could successfully launch via crond was to edit /etc/cron/crontabs/root using a unix editor to
from the telnet stop and start crond so the changes may take effectCode:#SHELL=/bin/sh 0 0 * * * /etc/dts.sh
This explains crond and the format it uses.Code:killall crond crond
I have no doubt there more efficient and correct ways of writing this script, but before today i had never touched a bash script and knew only a couple of unix commands...
Cheers, RHCP.
Democracy: Three wolves and a sheep voting on what's for lunch.
Look Here -> |
Hi,
Thanks for the great script. I took it a made same improvements important for me:
-Ability to handle torrents that take more than 24 hours to download. The previous script opens a new ctorrent process each time it is executed and the .torrent file exists
-Connection to CTCS
The new script
Thanks.Code:#!/bin/sh stime=1 #Seed Time hrs port=1325 #Port +1 for each simultaneous download (ie 5000, 5001, 5002...5010...) cache=1 #MBs torrent cache URate=18 #In KB/S Set to 10% lower than max Up rate - Split evenly amongst multiple downloads DRate=999 #In KB/S Split evenly amongst multiple downloads - Set really high to max it MDownload=3 #Max Simultaneous downloads - any 'leftover' torrents will be kept and downloaded the next time TDir="/media/hdd/Torrents" #Where .torrent files are uploaded/kept TDown="/media/hdd/Torrents/Downloads" #Download dir LDir="/tmp" #Log dir DelTor=No # Yes or No - Delete .Torrent file after starting download Log=Yes # Yes or No - Logs output of ctorrent for each download to a file in log dir CtcsURL=192.168.1.2:2780 #CTCS Server URL. If you what to control your torrents via the CTCS web interface mkdir -p "$TDir" mkdir -p "$TDown" cd "$TDir" ls -1 *.torrent > tor1_temp if [ $? = 0 ] then TorData=`cat tor1_temp | tr '\n' '|'` lines=`wc -l tor1_temp| awk '{print $1}` rm tor1_temp if [ $MDownload -lt $lines ] then lines=$MDownload fi div=1 while [ $div -lt $lines ] do div=`expr $div + 1` done DRate=`expr $DRate / $div` URate=`expr $URate / $div` count=1 cd "$TDown" while [ $count -le $lines ] do Tor=`echo $TorData | cut -f$count -d"|"` processName=`echo $Tor | cut -c 1-20` resultcode=`ps | grep "$processName" |grep "ctorrent" |wc -l` if [ $resultcode = 0 ] then if [ $Log = Yes ] then ctorrent -X "$processName" -d -e $stime -C $cache -p $port -D $DRate -U $URate -S $CtcsURL "$TDir/$Tor" >> "$LDir/$Tor".txt & echo Starting to download $Tor >> "$LDir/$Tor".txt else ctorrent -X "$processName" -d -e $stime -C $cache -p $port -D $DRate -U $URate -S $CtcsURL "$TDir/$Tor" > /dev/null & fi else if [ $Log = Yes ] then echo $Tor is allready being downloaded >> "$LDir/$Tor".txt fi fi if [ $DelTor = Yes ] then mv "$TDir/$Tor" "$TDir/$Tor.OLD" fi port=`expr $count + $port` count=`expr $count + 1` done else rm tor1_temp exit fi
Thanks for the improvements, i like what you have done. Couple of questions, you are obviously using a different ctorrent to me, as theswitch in the ctorrent (in first post) im using gives an error as it displays meta-tag info. In enhanced ctorrent it supposedly runs $processName as a command. What ctorrent are you using, and what does the -X switch do?Code:-X
What platform are you running this on? Dreambox? If your using enhanced ctorrent, i would love to get a copy of a compiled version (i have no linux setup atm and don't want to compile it).
Also, what does thedo? If -X switch actually runs the $processName (which is first 20 letters of torrent title) as a command after download completion then i don't get what it does, or is -X used to give ctorrent process name (in ps) some part of the torrent name to identify it? Which would make sense as that's whatCode:ctorrent -X "$processName"seems to be looking for.Code:resultcode=`ps | grep "$processName" |grep "ctorrent" |wc -l` if [ $resultcode = 0 ]
Also, i had a problem with my script when downloading files which had long titles or certain characters...i did pinpoint the problem, but i haven't used it in ages and have now forgotten what caused it :P Have you experienced anything like this?
Thanks, RHCP.
Democracy: Three wolves and a sheep voting on what's for lunch.
Hi,
I use enhanced CTorrent on a Enigma 2 dreambox (DM800).
The reason to use the -X parameter is to identify the different ctorrent processes when executing the ps command. The output of the ps command, when executed as a cron, is generated with a limitation inthe number of columns (at least on my dreambox)
As you see, the right part of the ctorrent commans is not available. Very strange because happens to me only for ps commands executed in a cron. I googled but did not find a solution.Code:...... 2768 root 4244 S /usr/bin/CCcam_2.0.9 864 root 9780 S ctorrent -X GK.S01E01.HDTV.XviD- -d -e 48 -C 16 -p 1326 -D 199 -U 3 -S 192.168. 885 root 15204 S ctorrent -X GK.S01E02.HDTV.XviD- -d -e 48 -C 16 -p 1328 -D 199 -U 3 -S 192.168. 906 root 19764 S ctorrent -X GK.S01E03.HDTV.XviD- -d -e 48 -C 16 -p 1331 -D 199 -U 3 -S 192.168. 2647 root 372 S /bin/sh /usr/bin/enigma2.sh ..... 3256 root 12492 S ctorrent -X GK.S01E04.HDTV.XviD- -d -e 48 -C 16 -p 1331 -D 249 -U 4 -S 192.168. 10523 root 580 S telnetd
So the only way to kwow the .torrent files currently being downloaded by ctorrent processes is identifying them at the left part of the process command.
It's a pity because I was planning to use -X to run a script to delete *.torrent files but this was the only solution I found to associante .torrents to unix processes. Of course temp files could be used.... but I preffer current solution.
To avoid problems with long names or certain characters all references to file names must be quoted ("file name").
While coding the script I did not get any errors with the sample ctorrents I used, but reviewing the script I found a potential source of problems:
Should be changed to:Code:processName=`echo $Tor | cut -c 1-20`
I am not at home now and I cannot test this, but I think this is safer.Code:processName=`echo "$Tor" | cut -c 1-20`
Lgarrido
Hi, i'm having some probmelms to reach /etc/cron/crontabs/root my telnet session just says "permission denied" does anyone know how to solve this ?
i've also tried to just type /etc/dts.sh, but then it says "-sh: /etc/dts.sh: not found
"
please help,
Regards mr.Patel
Hi!
thanks it worked, but i would like to start the scritp manually and not like a timer.
so the app starts to download all torrents in the torrent folder and puts the files in the downloads folder. when i type a command in to the telnet box.
I'm using pli jade3 if thats intressting.
Thank you for the help
edit:
i have tried to save the
#SHELL=/bin/sh
***** /etc/dts.sh
but i don't know how to save after i've writtent crontab-e
i'm using putty on windows xp
Last edited by hiren; 07-07-09 at 02:49 AM.
yeah, but my box just says that ther is no. /etc/dts.sh
and i'm 100% shure that i've put it there.
chmod 755 /etc/dts.sh ???
Dm500, DM5620, DM600 x2, DM7000 x1, DM7020, DM7025, DM800, VU+DUO and a partridge in a pear tree
All it takes for evil to prevail is for good men to do nothing
Telnet into the box & enter "ll /etc"
You should see a line something like:
-rwxr-xr-x 1 root root 80 Jan 1 1970 dts.sh
in the output. The important parts are -rwxr-xr-x (the x's show that it is executable by owner (root), member of the group (root) and everyone else) and the last (dts.sh).
thanks, but yes i've already changed the chmod
the line is
-rwxr-xr-x 1 root root 1741 Jul 6 17:33 dts.sh*
wich seems to be correct?
but still when i write
/etc/dts.sh
the answear is -sh: /etc/dts.sh: not found
thank you for all help untill now
Can you type in the following and show us the result:
cd /
find . -name dts.sh
Bookmarks