PDA

View Full Version : Shell script...hope this is the right place....


robfindlay
February 4th, 2006, 05:18 AM
I need help creating either a perl or a bash script that will do the following.

When invoked scan the contents of a directory and put certain file names into a file. Sort of like what this would do:

ls -al *par2 > pars

then read that "pars" file one line at a time sort of like this:

sed -n '1p' pars, 2p, 3p, etc etc.

then once that file name is read it would need to evoke a command like

par2repair filename_read_from_pars_file.

you can see what I'm trying to get at.

I wrote a half assed bash script that basically excuted those commands the only problem is when i get to this part:

sed -n '1p' pars | par2repair

par2repair acts like it hasn't been given a par2 file to look at and issues an error, as if the sed command was inserting a carriage return somplace and causing par2repair to miss it.

btw cat pars | par2repair does the same thing.


Hope someone with some scripting skills can help me out i'm still pretty noobish.

TIA.

Rob

kabus
February 4th, 2006, 06:04 AM
Can't you just do

for i in *{par2,PAR2}; do par2 r "$i"; done

?

joft
February 4th, 2006, 06:12 AM
par2repair filename_read_from_pars_file.

you can see what I'm trying to get at.

I wrote a half assed bash script that basically excuted those commands the only problem is when i get to this part:

sed -n '1p' pars | par2repair

Are you sure that par2repair (whatever that is) is able to read filenames from stdin (standard input)? In the first line quoted above, you give the filename as the first argument to par2repair. But in the last line quoted above, you assume that par2repair is reading filenames from stdin.

Assuming par2repair is reading a filename from the first argument, I would do:

par2repair `sed -n '1p' pars`

Which will execute par2repair with the first filename in your file "pars".

Or am I getting you wrong?

toojays
February 4th, 2006, 06:55 AM
How about "find . -name '*.par2' -exec par2repair '{}' ';'"?

robfindlay
February 4th, 2006, 01:29 PM
Can't you just do

for i in *{par2,PAR2}; do par2 r "$i"; done

?

Oh holy crap that did it! Can you break your code down for this newb so i can understand whats up?

Its obvious your reading directly from the directory but beyond that i'm lost....i've barely just started trying to learn perl and so bash scripting is a mystry to me altogehter.



Okay, one other thing, what if I wanted this to run continuously in a loop? Maybe pausing for an hour at the end and then restarting at the top ?

What'd i'd really love is an automation script that checks an entire RAR set with par2's and then when its complete excutes unrar to extract the files. ;-)

Rob

robfindlay
February 4th, 2006, 06:12 PM
Can someone give me the basics on how to loop such a script ?

Meaning execute, wait like an hour and then start over.


Rob

kabus
February 4th, 2006, 06:52 PM
Oh holy crap that did it! Can you break your code down for this newb so i can understand whats up?

It's just a simple for loop. Take a look here for a better explanation than I could come up with :) :

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_01.html

Okay, one other thing, what if I wanted this to run continuously in a loop? Maybe pausing for an hour at the end and then restarting at the top ?

I guess you could use a while loop (while true; do ...;done) or run a cron job once an hour :

https://wiki.ubuntu.com/CronHowto

BTW, I guess you want to process usenet downloads. Check out hellanzb, it does all the par/rar stuff automatically :

http://www.hellanzb.com/trac/

robfindlay
February 4th, 2006, 06:59 PM
It's just a simple for loop. Take a look here for a better explanation than I could come up with :) :

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_01.html



I guess you could use a while loop (while true; do ...;done) or run a cron job once an hour :

https://wiki.ubuntu.com/CronHowto

BTW, I guess you want to process usenet downloads. Check out hellanzb, it does all the par/rar stuff automatically :

http://www.hellanzb.com/trac/

Oh great now you tell me....lol :-)

What i think i'll use is "watch" to execute the script in a screen session.


Now if I can just get somthing more stable then PAN i can kiss windows goodbye.

robfindlay
February 4th, 2006, 08:17 PM
It's just a simple for loop. Take a look here for a better explanation than I could come up with :) :

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_01.html



I guess you could use a while loop (while true; do ...;done) or run a cron job once an hour :

https://wiki.ubuntu.com/CronHowto

BTW, I guess you want to process usenet downloads. Check out hellanzb, it does all the par/rar stuff automatically :

http://www.hellanzb.com/trac/


Have you been able to get hellanzb to work under breezy? I downloaded the tarball but when I run the setup.pl i get an error about a missing MakeFile.

If you've gotten it running could you be so kind as to post up a how-to or perhaps msg me with it offline?


Rob

kabus
February 4th, 2006, 08:42 PM
As far as I remember you'll have to install the python-dev and python-twisted packages to make it work.

GrinRoth
April 14th, 2006, 08:21 AM
As far as I remember you'll have to install the python-dev and python-twisted packages to make it work.

Thanks m8!
I was trying to get this very handy program to work on Dapper and it didn't work.
But with those 2 packages installed, everything going fine! :-D