Hack Forums
[Shell] Upload .torrent files to your seed server - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] Upload .torrent files to your seed server (/showthread.php?tid=4559282)



Upload .torrent files to your seed server - bsdpunk - Nov 28, 2014

So let's say over the course of the day you download a lot of .torrent files and you need to upload them to your seebox, this is how I do it, via a crond job. This uploads all the .torrent files in the ~/Downloads directory:

Code
for i in $(find ~/Downloads -newermt "2014-11-07" | grep "torrent$" ); do scp -r $i bsdpunk@seedbox:/home/disk1/bsdpunk/torrents/watch; done



* - 'Palladium - Nov 28, 2014

Nice script OP, you mind explaining what the code exactly does and works?


* - b00st3d - Nov 30, 2014

(Nov 28, 2014 08:39 PM)HacksBro Wrote:  Nice script OP, you mind explaining what the code exactly does and works?

This looks like a shell script that loops through and finds all .torrent files newer than 2014-11-07 that reside in the Downloads in the users home dir. It then uses SCP (secure copy) to transfer the .torrent to the user's seedbox at the specified location.


* - Loki123 - Dec 4, 2014

I'd rather have all my content organized perfectly and then use rsync to pull the data from my machine everyday with cron. Just how I prefer to do it.
Or you can get cron and SSH on a seedbox right ? never used one.


* - bsdpunk - Dec 6, 2014

So yeah doing an rsync to get your data with a cron is great. But this is for putting the .torrents in your watch directory that you recently downloaded.


* - DJMODZ - Dec 6, 2014

not a bad setup, you could also work with something like this:

Code
watch_dir=~/Downloads
upload_dir=/home/disk1/bsdpunk/torrents/watch
sleep_duration=10
spin='-\|/'

i=0
while true
do
    saveifs=$IFS
    IFS=$(echo -en "\n\b")
    files=$(ls -a $watch_dir*.{torrent} 2> /dev/null)

    if [ ${#files} -eq 0 ]; then
      i=$(( (i+1) %4 ))
      printf "\r[${spin:$i:1}] %s" `date +%Y-%m-%d:%H:%M:%S`
    fi

    for f in $files
    do
      lsof $f > /dev/null
      if [ $? -eq 1 ]; then
                      echo
      scp -r $f bsdpunk@seedbox:$upload_dir
      else
      sleep_duration=1
      i=$(( (i+1) %4 ))
      printf "\r[${spin:$i:1}] %s is being written" $(basename $f)
      fi
    done
    IFS=$saveifs
done

You just need to run this once and leave it in the background, screen would be ideal for this

SSH Keys also make this automated, which I presume you already setup, but forgot to mention ;)


* - bsdpunk - Dec 6, 2014

So I have a similar setup I showed here:
https://hackforums.net/showthread.php?tid=4572034

but yeah it's wicked awesome, and I have ssh keys set up.

But much love @djmodz