DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2007-03-23 03:58:49

Stampeed
Member
Registered: 2006-12-10
Posts: 13

torrent shell script

just thought i'd give it...

if anyone can find a way for it to automatically select a port, lemme know. it's been a while since i wrote shell scripts.

Usage: run_torrent.sh <port> <torrent>

Ex. run_torrent.sh 6881 Various_Artists_-_Music_Album.torrent

Code:

#!/bin/sh

#
# DSM-G600 ctorrent running script v1
# 
#

###############################################################
# CONFIGURATION SECTION
###############################################################
#
# Set 'auto_detect_ip' to 1 to automatically attempt to find 
# the DSM-G600's IP address
# Or set it to 0 and configure the local IP address manually
# by modifying local_ip to your static IP.
#
auto_detect_ip=1
local_ip="192.168.1.100"

#Unimplemented
#auto_detect_port=1

###############################################################
# DO NOT MODIFY ANYTHING BELOW THIS LINE
###############################################################

if [ ! $2 ]
then
    echo "Usage: $0 <port> <torrent>"
    return
fi

if [ $auto_detect_ip -eq 1 ] 
then
    ifconfig_text=`/sbin/ifconfig`
    #echo $ifconfig_text

    local_ip=${ifconfig_text#*eth0 *inet addr:}
    local_ip=${local_ip%% *}
fi

local_port=$1

#Code for auto-detecting port here

echo "Running torrent $2 on $local_ip:$local_port"

#echo "nohup ctorrent -e 0 -C 4 -i $local_ip -p $local_port \"$2\" > $2.out &"
nohup ctorrent -e 0 -C 4 -i $local_ip -p $local_port "$2" > $2.out &

This script provides a way to automatically set the IP address, i'd also like a way to automatically set a port.

The only way I can think of automatically finding an open port is to:
1) have the user fill an array with the ports he/she has opened up on their router

Code:

#auto_detect_port=1
#valid_ports={6881 6882 6883 6884 6885 6886 6887 6888 6889}

2) capture the text from the "ps -e" command, then extract each line with ctorrent in it and extract the port number

Code:

ps_text=`ps -e`

3) Remove each of those ports from the array of user selected ports,

Code:

 ?? anybody ?

4) Then if there are any ports left in the array, pick one and run the torrent using it, otherwise error out.

Code:

 ?? :-) again, anybody?

someone wanna script that up for me?
it's been ages since i've used arrays in linux shell scripts.

thanks,

Offline

 

#2 2007-07-07 15:22:48

dlu_tm
New member
Registered: 2007-05-31
Posts: 3

Re: torrent shell script

I tried your script but I noticed that if I run ctorrent with nohup, it uses 99% CPU.  However, if I don't run ctorrent with nohup then the CPU usage is less than 1%.

Is there anyway to run cturrent with nohup without using 99% CPU?

Offline

 

#3 2007-09-27 18:27:44

sala
Member / Site Admin
From: Estonia
Registered: 2006-07-28
Posts: 731
Website

Re: torrent shell script

nohup is writing output to somewhere in real-time, you may try to sent output to /dev/null
This may help.


DSM-G600 - NetBSD hdd-boot - 80GB Samsung SP0802N
NSA-220 - Gentoo armv5tel 20110121 hdd-boot - 2x 2TB WD WD20EADS

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB