LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-24-2005, 01:56 PM   #1
kyosuke
LQ Newbie
 
Registered: Jun 2005
Distribution: Fedora Core 3
Posts: 9

Rep: Reputation: 0
Automating Bittorrent with shell scripts


Hi all,

I use a headless Fedora Core 3 box to run bittorrent downloads on. I'm using 'btlaunchmany' running as a background process so I can just drop .torrent files into a folder and it starts downloading automatically.

I'd like, however, to automate the process further. Specifically, I'd like to have a script I can run as a cron job that will scan the log file and delete the .torrent file for downloads that have finished.

A line of output in the log file for a finished torrent looks like this:

Quote:
"/mnt/storage/Current Downloads/example.torrent": "seeding" (100.0%) - 33P0s7.000D u13.6K/s-d0.0K/s u498400K-d2346300K ""
I want the script to look for the word 'seeding' on a line in the log file and delete the file /mnt/storage/Current\ Downloads/example.torrent. However I'm not sure exactly how to go about this. Any hints to point me in the right direction would be appreciated.

Also appreciated would be tips on how to implement a download queue. Say for example I want no more than 4 downloads running at one time, but I have several .torrent files queued in another folder. If one download completes and is removed by the removal script, the queue script would detect that there are less than 4 downloads and move the oldest .torrent file from the queue directory to the download directory (the one monitored by btlaunchmany) where it would then be downloaded. Again, I'm not sure how I might go about this, but it would be cool to have, yes?
 
Old 06-26-2005, 02:38 AM   #2
makuyl
Senior Member
 
Registered: Dec 2004
Location: Helsinki
Distribution: Debian Sid
Posts: 1,107

Rep: Reputation: 54
Hmm, a script that automates leeching. Why would you want to do that?
 
Old 06-30-2005, 10:15 AM   #3
kyosuke
LQ Newbie
 
Registered: Jun 2005
Distribution: Fedora Core 3
Posts: 9

Original Poster
Rep: Reputation: 0
Ok, I'll bite.

I want this script because I'm on a residential broadband connection with finite upstream bandwidth and I still want to use it for other things besides torrents. That's not to say however that I'm a complete leech. I still share quite well while downloading. Furthermore if this were set to run as a daily cron job most all of the torrents I run on it would be seeded for quite some time after finishing, likely to match the amount of downloaded data or better.

I mean, all torrents have to be removed at some point and I download a lot of them. I'm all for seeding, but considering the size of my upstream, I hardly think the 2KB/s I'd be contributing if I seeded 10 torrents would be worth it. This is just about automating their removal so I don't have to do it myself daily, the computer can do it for me.
 
Old 06-30-2005, 01:28 PM   #4
Vgui
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware
Posts: 496

Rep: Reputation: 31
You could try grepping for your keyword of "seeding" in the log, then using sed (check it's man page, it's basically a string manipution program) to get the filename from the return of grep, then delete the filename. If this was a cron job as you say, it would eventually delete the torrent file and stop it from seeding (unless the file is in use, that might bring up issues).

pseudo code:
grep the log for seeding
if found, sed out the path
remove the torrent file at the found path
?maybe remove the line from the log?

Hope that points you in the right direction.
 
Old 07-01-2005, 10:14 AM   #5
makuyl
Senior Member
 
Registered: Dec 2004
Location: Helsinki
Distribution: Debian Sid
Posts: 1,107

Rep: Reputation: 54
Hmm, I suppose you really can justify not uploading if it doesn't make any difference to others anyway. Sort of a moral question really.

I don't know what the lines look like that don't contain "seeding", I guessed "downloading", so here's something to start with. Surely it can be improved upon, and use at your own risk

#!/bin/sh
sed -i '/seeding/s/"//;/seeding/s/".*//' /path/to/logfile
grep -v 'downloading' /path/to/logfile | xargs rm
sed -i '/downloading/!d' /path/to/logfile
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Automating the "killing" process via a shell script fatrandy13 Linux - Software 5 09-13-2007 11:59 PM
automating lynx in a shell script yimboli Programming 15 04-04-2007 02:15 AM
Trouble when automating ftp with shell script hari_s_82 Linux - Newbie 2 09-23-2004 02:17 AM
automating using shell scripting LinToWinWin Linux - Newbie 1 07-23-2004 09:57 PM
Automating a playlist using shell script... DesiLILO Linux - Newbie 4 04-02-2004 11:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration