richsark
asked on
Help with my perl script
hello, I have this script but it fails to run. It was orginaly set to run on a unix box( See below), so I changed the path to my my windows path wihere my input file is located.
When I run it, it fails to look at my directory where the files are located.
My input file is located at c:\named.conf-rich
Can someone fix this so it will run on my windows box.
Thanks
When I run it, it fails to look at my directory where the files are located.
My input file is located at c:\named.conf-rich
Can someone fix this so it will run on my windows box.
Thanks
#!/perl
unless ($ARGV[0]) {
print "******************************************************\n";
print "* *\n";
print "* *\n";
print "******************************************************\n";
exit;
}
$inputfile=$ARGV[0];
$zonefound = 0;
open(INFILE, $inputfile) or die "Unable to find $inputfile\n";
@conf = <INFILE>;
close INFILE;
foreach $linein (@conf) {
chomp($linein);
$count++;
if ($linein =~ /^zone\s+\".*in-addr.arpa\"/) {
$countZONE++;
$zonefound = 1;
($j1, $j2, $j3, $j4, $j5) = split " ",$linein;
#print "ZONE-START: $linein\n";
}
elsif (($zonefound == 1) and ($linein =~ /^\}/)) {
$zonefound = 0;
#print " ZONE-END: $linein\n";
}
elsif (($zonefound == 1) and ($linein =~ /allow-update/)) {
print "$j2,$linein\n";
}
else {
next;
};
};
Do you get an error when you run it?
ASKER
Hi,
Well, first I am unsure of the $input file in terms of what I need to set. I do know that my input file is located in c:\named.conf\-rich
In that directory I have tons of file called
named.conf.6cmghnsrt01.net
What this script will do is look at the contents of what is directed.
So, I want to make sure when I run this script, I need it to look at the directory c:\named.conf\-rich and look at all the files that begin with named.conf and pull out what the script does.
I think the script runs with script name and filename, checkconf.pl
named.conf.6cmghnsrt01.net
I do not want it to do that. I want it to look in my dir and do it automaticlay.
Thanks
do you want to read @ARGV=<c:/named.conf/-rich /*>?
how would you have done what you are trying to do in unix?
the code snippet does not seem to match your description.
how would you have done what you are trying to do in unix?
the code snippet does not seem to match your description.
ASKER
Hi, yes, My script for unix is what I want to make work for my needs. The script I have is a baseline which I think is close to what I need.
So, yes my input file is c:\named.conf-rich which will contain all the files I need for this script to read.
Thanks Ozo
So, yes my input file is c:\named.conf-rich which will contain all the files I need for this script to read.
Thanks Ozo
ASKER
hi, does that help?
The script you posted expects you to give it the name of a file as a command line argument, like so:
script.pl c:\named.conf-rich\list.tx t
The script then reads that file, and counts the number of zones (lines beginning with "zone") in them.
script.pl c:\named.conf-rich\list.tx
The script then reads that file, and counts the number of zones (lines beginning with "zone") in them.
ASKER
Hi Adam, I know , I want it to read a specific directory and work from there. That is why I needed this script to be slightly re-worked.
I rather have this script work in a wau where I excute the script, it will look in my directory, in this case c:\named.conf-rich
In there it will find all the files that start with named.conf.xxxxx and spit out what its designed to do from there.
Does that sound do'able
I rather have this script work in a wau where I excute the script, it will look in my directory, in this case c:\named.conf-rich
In there it will find all the files that start with named.conf.xxxxx and spit out what its designed to do from there.
Does that sound do'able
#open(INFILE, $inputfile) or die "Unable to find $inputfile\n";
#@conf = <INFILE>;
#close INFILE;
#foreach $linein (@conf) {
@ARGV=<$inputfile/named.co nf.*>;
while( $linein=<> ){
#@conf = <INFILE>;
#close INFILE;
#foreach $linein (@conf) {
@ARGV=<$inputfile/named.co
while( $linein=<> ){
ASKER
Hi Ozo, so this will go like this in my scirpt
#!/perl
unless ($ARGV[0]) {
print "******************************************************\n";
print "* *\n";
print "* *\n";
print "******************************************************\n";
exit;
}
#open(c:\named.conf-rich, $inputfile) or die "Unable to find $inputfile\n";
#@conf = <INFILE>;
#close INFILE;
#foreach $linein (@conf) {
@ARGV=<$c:/named.conf-rich/named.conf.*>;
while( $linein=<> ){
foreach $linein (@conf) {
chomp($linein);
$count++;
if ($linein =~ /^zone\s+\".*in-addr.arpa\"/) {
$countZONE++;
$zonefound = 1;
($j1, $j2, $j3, $j4, $j5) = split " ",$linein;
#print "ZONE-START: $linein\n";
}
elsif (($zonefound == 1) and ($linein =~ /^\}/)) {
$zonefound = 0;
#print " ZONE-END: $linein\n";
}
elsif (($zonefound == 1) and ($linein =~ /allow-update/)) {
print "$j2,$linein\n";
}
else {
next;
};
};
no,
#foreach $linein (@conf) {
should be commented out
and $c would need to be defined.
If you are not reading $c = $ARGV[0];
instead of $inputfile=$ARGV[0];
then you could code the path you want into the <>
#foreach $linein (@conf) {
should be commented out
and $c would need to be defined.
If you are not reading $c = $ARGV[0];
instead of $inputfile=$ARGV[0];
then you could code the path you want into the <>
ASKER
Hi Ozo, can you please put the final code below so there is not to much back and forth.
I appericate it Ozo/Adam
Thanks
I appericate it Ozo/Adam
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Awsome, so where it says
#@conf = <INFILE>;
I need to put:
@conf = <c:\named.conf-rich>;
#@conf = <INFILE>;
I need to put:
@conf = <c:\named.conf-rich>;
In the new code, @conf isn't used. This line:
@ARGV=<c:/named.conf-rich/ named.conf .*>;
is the line that searches for the files named c:\named.conf-rich\named.c onf.*.
Then this line:
while( $linein=<> ){
is what reads from those files, one line at a time.
@ARGV=<c:/named.conf-rich/
is the line that searches for the files named c:\named.conf-rich\named.c
Then this line:
while( $linein=<> ){
is what reads from those files, one line at a time.
No, that's not what I wrote.
But now I'm getting confused
But is c:\named.conf-rich a text file or a directory
But now I'm getting confused
But is c:\named.conf-rich a text file or a directory
ASKER
ok, so we can assume this puppy will work as below
#!/perl
#unless ($ARGV[0]) {
# print "******************************************************\n";
# print "* *\n";
# print "* *\n";
# print "******************************************************\n";
# exit;
#}
#$inputfile=$ARGV[0];
$zonefound = 0;
#open(INFILE, $inputfile) or die "Unable to find $inputfile\n";
#@conf = <INFILE>;
#close INFILE;
#foreach $linein (@conf) {
@ARGV=<c:/named.conf-rich/named.conf.*>; #i ignore $inputfile=$ARGV[0];
and always look for c:/named.conf-rich/named.conf.*
while( $linein=<> ){
chomp($linein);
$count++;
if ($linein =~ /^zone\s+\".*in-addr.arpa\"/) {
$countZONE++;
$zonefound = 1;
($j1, $j2, $j3, $j4, $j5) = split " ",$linein;
#print "ZONE-START: $linein\n";
}
elsif (($zonefound == 1) and ($linein =~ /^\}/)) {
$zonefound = 0;
#print " ZONE-END: $linein\n";
}
elsif (($zonefound == 1) and ($linein =~ /allow-update/)) {
print "$j2,$linein\n";
}
else {
next;
};
};
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, will get back when a few
#If I'm understanding what you are doing, it looks like your entire program may be
@ARGV=<c:/named.conf-rich/ named.conf .*>;
(($j2)=/^zone\s+(".*in-add r.arpa")/) .. /^}/ and /allow-update/ and print "$j2,$_" while <>;
@ARGV=<c:/named.conf-rich/
(($j2)=/^zone\s+(".*in-add
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent work !