|
OJK
Stranger

Registered: 06/08/03
Posts: 10,629
|
linux shell script help
#5659558 - 05/22/06 09:41 AM (17 years, 8 months ago) |
|
|
hey,
can anyone give me some pointers on writing a basic linux shell script? Bear in mind, I'm a linux n00b, so be nice 
I'm trying to run "bittorrent-console.py" with a number of variables filled in before hand, but some set at the time the script runs.
I thought something like this might do it;
Quote:
#bittorrent script
$ python bittorrent-console.py --responsefile /%t --save_as /%s --minport 59000 --maxport 62000 --rerequest_interval 15 --display_interval 5 --max_upload_rate /%u
I was hoping that I could save that to script.sh in the same directory as the bittorrent python files, then execute it with something like
$ ah script.sh -t *.torrent -s * -u *
obviously this doesn't work
can anyone give me some pointers? I've had a look at some guides, but they're all kind of dense and start from the novel position that I'm not an idiot 
thanks for any help
|
Krishna
कृष्ण,LOL


Registered: 05/08/03
Posts: 23,285
Loc: oakland
|
Re: linux shell script help [Re: OJK]
#5661680 - 05/22/06 08:29 PM (17 years, 8 months ago) |
|
|
ok, you want something like
Code:
#!/bin/sh /usr/bin/python bittorrent-console.py --responsefile $1 --save_as $2 --minport 59000 --maxport 62000 --rerequest_interval 15 --display_interval 5 --max_upload_rate $3
and you'd run it (after chmod'ing exec the script, and assuming it is in the same dir as the .torrent files) via
Code:
./script.sh *.torrent *.mp3 500
or whatever the params were.
you can use $1-$9 for command line args ($0 is the script itself). anymore than that, and you'll have to start shifting. i'm not completely sure if the $1 will work with a wildcard (*) input, though..
this might help..
--------------------
|
OJK
Stranger

Registered: 06/08/03
Posts: 10,629
|
Re: linux shell script help [Re: Krishna]
#5663035 - 05/23/06 05:05 AM (17 years, 8 months ago) |
|
|
thanks man, I'll give it a shot
|
Seuss
Error: divide byzero


Registered: 04/27/01
Posts: 23,480
Loc: Caribbean
Last seen: 2 months, 20 days
|
Re: linux shell script help [Re: OJK]
#5663076 - 05/23/06 05:49 AM (17 years, 8 months ago) |
|
|
You may have to make the script executable before you can run it:
% chmod 700 ./script.sh
"chmod" is used to change the file permissions. The 700 tells the system to give the user read, write, and execute permissions while removing all premissions for everybody else. You must be the file owner, or root, to make the change.
Make certain that there is no blank lines or spaces between the top of the script and the #!/bin/sh. These must be the very first characters in the script.
-------------------- Just another spore in the wind.
|
OJK
Stranger

Registered: 06/08/03
Posts: 10,629
|
Re: linux shell script help [Re: Seuss]
#5663142 - 05/23/06 06:38 AM (17 years, 8 months ago) |
|
|
I thought that the "#" commented out anything after it?
I had kind of assumed that. If it's not "#", what's the comment charecter for shell scripts? Is it "::" as with batch files?
Thanks
|
Seuss
Error: divide byzero


Registered: 04/27/01
Posts: 23,480
Loc: Caribbean
Last seen: 2 months, 20 days
|
Re: linux shell script help [Re: OJK]
#5663185 - 05/23/06 07:11 AM (17 years, 8 months ago) |
|
|
For any line but the very first line in a shell script, the # is a comment. For the first line of a shell script, the # is part of the "magic number" that identifies the interpreter to be run to process the script. That is why it is important that there be no lines or spaces between the top of the script and the #!/bin/sh line.
You can use the "file" command to test this:
% file good.sh good.sh: a /bin/sh script text executable
% file bad.sh bad.sh: ASCII text
-------------------- Just another spore in the wind.
|
OJK
Stranger

Registered: 06/08/03
Posts: 10,629
|
Re: linux shell script help [Re: Seuss]
#5664094 - 05/23/06 12:06 PM (17 years, 8 months ago) |
|
|
ok, thanks for the help guys
this script seems to do what I want it to -
Code:
#!/bin/sh python mine/BitTorrent-4.4.0/bittorrent-console.py --responsefile mine/BitTorrent-4.4.0/$1 --save_as mine/BitTorrent-4.4.0/$2 --minport 59000 --maxport 62000 --rerequest_interval 15 --display_interval 5 --max_upload_rate $3
I've uploaded it to my home directory (on the shared server, my home directory is /home/[username]).
I run it with;
Code:
$ sh bt.sh openoffice.torrent openoffice.rar 100
and it seems to work 
It's probably not the tidiest solution, but it appears to get things done. I just dump everything into my bittorrent directory at the moment.
thank you 
p.s. am I doing anything wrong?
|
OJK
Stranger

Registered: 06/08/03
Posts: 10,629
|
Re: linux shell script help [Re: OJK]
#5664176 - 05/23/06 12:21 PM (17 years, 8 months ago) |
|
|
SHIT!
I've been using the "screen" program of debian to leave torrents running when I'm logged off the server. However, it seems that I can only have six "screen" virtual terminals running in the background at a time - when I start a new screen terminal when there are six already running, one of the existing ones dies.
How can I stop this and run more than six at a time?
|
|