mikeym
July 16th, 2006, 01:15 PM
Hi,
Sorry this is my second thread on this toppic but I posted the last one in the General thread and realised that it was in the wrong place, but I don't know how to move it.
I'm trying to write my first propper BASH script at the moment and I am stuck with a few things.
Firstly (covered)
I am trying to use a for loop to call a script once for each file in a directory, but when I run it it is calling the script once for all 3 files.
I want to run it like a script like this:
#!/bin/sh
nzbperl.pl "/mp3/dvd/nzb/TestR.nzb" 2>> /dev/null
echo "$?"
nzbperl.pl "/mp3/dvd/nzb/TestF.nzb" 2>> /dev/null
echo "$?"
nzbperl.pl "/mp3/dvd/nzb/TestO.nzb" 2>> /dev/null
echo "$?"
This results in the nzbperl.pl script being run 3 times.
But my code results in it being run once and passed a parameter for all 3 files.
for NZBFILE in "$(find /mp3/dvd/nzb -iname *.nzb -maxdepth 1 2> /dev/null)"; do
echo "$NZBFILE"
date +"%F %T Running 'nzbperl.pl'." >> /var/log/getnzbfiles.log
nzbperl.pl "$NZBFILE" 2>> /dev/null
echo "$?"
done
How can I force it to run nzbperl.pl 3 separate times?
Secondaly (covered)
I am trying to ouput a command usage list but when I try to format it with tabs it ignores them or doesn't do the substitutions.
function PrintUseage {
echo "Useage: \t $0 [options]"
echo "Options:"
echo "-cron \t Restrict graphical output for cron."
echo "-shutdown \t Shutdown the computer on completion."
}
Creates the output;
Useage: \t /home/mikey/bin/getnzbfiles.sh [options]
Options:
-cron \t Restrict graphical output for cron.
-shutdown \t Shutdown the computer on completion.
Thirdly (Not possible)
I want to interperate the nzbperl.pl script's ouput to understand how it has exited. The a call to "echo $?" to get an error afer the script has exited abnormally still returns 0, so I think it doesn't use error return codes. The nzbperl.pl script uses a graphical interface so I don't think I can direct it to file without it getting too big, and the error output gives many readings in the same way.
Is there a way to capture the begning of the output just so I can get that before it starts trying to do graphics?
Here is an ouput where it encounters an error:
Sorry, but nzb file is broken! The xml could not be parsed:
Couldn't open /mp3/dvd/nzb/TestR.nzb
/mp3/dvd/nzb/TestF.nzb
/mp3/dvd/nzb/TestO.nzb:
No such file or directory at /usr/local/bin/nzbperl.pl line 2126
*** nzbperl requires valid, well-formed XML documents.
Sorry this is my second thread on this toppic but I posted the last one in the General thread and realised that it was in the wrong place, but I don't know how to move it.
I'm trying to write my first propper BASH script at the moment and I am stuck with a few things.
Firstly (covered)
I am trying to use a for loop to call a script once for each file in a directory, but when I run it it is calling the script once for all 3 files.
I want to run it like a script like this:
#!/bin/sh
nzbperl.pl "/mp3/dvd/nzb/TestR.nzb" 2>> /dev/null
echo "$?"
nzbperl.pl "/mp3/dvd/nzb/TestF.nzb" 2>> /dev/null
echo "$?"
nzbperl.pl "/mp3/dvd/nzb/TestO.nzb" 2>> /dev/null
echo "$?"
This results in the nzbperl.pl script being run 3 times.
But my code results in it being run once and passed a parameter for all 3 files.
for NZBFILE in "$(find /mp3/dvd/nzb -iname *.nzb -maxdepth 1 2> /dev/null)"; do
echo "$NZBFILE"
date +"%F %T Running 'nzbperl.pl'." >> /var/log/getnzbfiles.log
nzbperl.pl "$NZBFILE" 2>> /dev/null
echo "$?"
done
How can I force it to run nzbperl.pl 3 separate times?
Secondaly (covered)
I am trying to ouput a command usage list but when I try to format it with tabs it ignores them or doesn't do the substitutions.
function PrintUseage {
echo "Useage: \t $0 [options]"
echo "Options:"
echo "-cron \t Restrict graphical output for cron."
echo "-shutdown \t Shutdown the computer on completion."
}
Creates the output;
Useage: \t /home/mikey/bin/getnzbfiles.sh [options]
Options:
-cron \t Restrict graphical output for cron.
-shutdown \t Shutdown the computer on completion.
Thirdly (Not possible)
I want to interperate the nzbperl.pl script's ouput to understand how it has exited. The a call to "echo $?" to get an error afer the script has exited abnormally still returns 0, so I think it doesn't use error return codes. The nzbperl.pl script uses a graphical interface so I don't think I can direct it to file without it getting too big, and the error output gives many readings in the same way.
Is there a way to capture the begning of the output just so I can get that before it starts trying to do graphics?
Here is an ouput where it encounters an error:
Sorry, but nzb file is broken! The xml could not be parsed:
Couldn't open /mp3/dvd/nzb/TestR.nzb
/mp3/dvd/nzb/TestF.nzb
/mp3/dvd/nzb/TestO.nzb:
No such file or directory at /usr/local/bin/nzbperl.pl line 2126
*** nzbperl requires valid, well-formed XML documents.