CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Modify perl script with report and count

 



richsark
User

Jun 15, 2009, 6:18 PM

Post #1 of 16 (1559 views)
Modify perl script with report and count Can't Post

Hi, I need some help to tweak this script to provide me some additional information.

I would like a way for the report to look like this if there is content found in pre/postfix section of this script

domain,#records,#A,#CNAME,#MX,#TXT,#SRV,#PTR,#OTHER

Then spit out a file for each domain name.txt ( add a .txt extension to whatever domain it creates) and in that sort it for each record type found:

For example:

If a file was created for sark.com.txt, once I open it, I like it to look as such:

Total number if records found 2

They are:
100CLIP.sark.net IN CNAME sarkie123.dcf.gis.sark.com.
richsark IN A 200.2.200.1

Thank you !


Code
#!perl -w 
my @revlist = `./exportdomain.exe -u 123 -p 123 -o srs`;
shift @revlist;
my $report = "";
my @domains;
my @includes;
foreach(@revlist) {
next unless /(.*?),(.*)$/;
my $domain_name = $1;
push @domains, $domain_name;

print "Checking $domain_name\n";
my $txt = `./grabzoneext.exe -u 111 -p 111 -n $domain_name -o srs 2>&1`;
$txt =~ s/[\r\n]+/\n/gs;
my $prefix = ($txt =~ /ParameterName=Prefix[^\r\n]+?[\r\n]+(.*?)(?:OptionType|ParameterName|$)/si) ? $1 : 0;
my $postfix = ($txt =~ /ParameterName=Postfix[^\r\n]+?[\r\n]+(.*?)(?:OptionType|ParameterName|$)/si) ? $1 : 0;
my $include = ($txt =~ /\$INCLUDE\s*([^\r\n]+?)[\r\n]/si) ? $1 : 0;

# if you don't want to print domains without prefix or postfix uncomment the next line
# next unless $prefix || $postfix;

$report .= "Domain $domain_name\n";
$report .= "Prefix:\n$prefix\n" if $prefix;
$report .= "Postfix:\n$postfix\n" if $postfix;
$report .= "\$INCLUDE:\n$include\n" if $include;
$report .= "No options found\n" unless $prefix || $postfix ||$include;
push @includes, [$domain_name, $include] if $include;
}

open(my $out, ">domain-inspection-6-2-09.txt") or die "Could not open output: $!\n";
print $out "Summary -- domains found = ".scalar(@domains);
print $out "\n\nSummary -- \$INCLUDEs:\n";
print $out "\$INCLUDE ".$_->[1]." found in domain ".$_->[0]."\n" foreach (@includes);
print $out "\nFull Report:\n";
print $out $report;
close($out);



(This post was edited by richsark on Jun 15, 2009, 6:22 PM)


richsark
User

Jun 16, 2009, 6:48 AM

Post #2 of 16 (1551 views)
Re: [richsark] Modify perl script with report and count [In reply to] Can't Post

Hello,

I have this:

Code
$report .= (join",",$domain_name,map{scalar(()=$txt=~/\s+IN\s+$_.*/g)}(qr/./,qr/A/,qr#CNAME#,qr#MX#,qr#TXT#,qr#SRV#,qr#PTR#,qr#OTHER#))."\n";


which I incorporated like so:

#!perl -w
my @revlist = `./exportdomain.exe -u 123 -p 123 -o srs`;
shift @revlist;
my $report = "";
my @domains;
my @includes;
foreach(@revlist) {
next unless /(.*?),(.*)$/;
my $domain_name = $1;
push @domains, $domain_name;

print "Checking $domain_name\n";
my $txt = `./grabzoneext.exe -u 111 -p 111 -n $domain_name -o srs 2>&1`;
$txt =~ s/[\r\n]+/\n/gs;
my $prefix = ($txt =~ /ParameterName=Prefix[^\r\n]+?[\r\n]+(.*?)(?:OptionType|ParameterName|$)/si) ? $1 : 0;
my $postfix = ($txt =~ /ParameterName=Postfix[^\r\n]+?[\r\n]+(.*?)(?:OptionType|ParameterName|$)/si) ? $1 : 0;
my $include = ($txt =~ /\$INCLUDE\s*([^\r\n]+?)[\r\n]/si) ? $1 : 0;

# if you don't want to print domains without prefix or postfix uncomment the next line
# next unless $prefix || $postfix;

$report .= (join",",$domain_name,map{scalar(()=$txt=~/\s+IN\s+$_.*/g)}(qr/./,qr/A/,qr#CNAME#,qr#MX#,qr#TXT#,qr#SRV#,qr#PTR#,qr#OTHER#))."\n";
push @includes, [$domain_name, $include] if $include;
}

open(my $out, ">domain-inspection-6-2-09.txt") or die "Could not open output: $!\n";
print $out "Summary -- domains found = ".scalar(@domains);
print $report;
print $out "\n\nSummary -- \$INCLUDEs:\n";
print $out "\$INCLUDE ".$_->[1]." found in domain ".$_->[0]."\n" foreach (@includes);
print $out "\nFull Report:\n";
print $out "domain,#records,#A,#CNAME,#MX,#TXT,#SRV,#PTR,#OTHER\n";
print $out $report;

close($out);

Code
 
The domain-inspection-6-2-09.txt looks like this now:

Summary -- domains found = 3

Summary -- $INCLUDEs:

Full Report:

sark-usa.rich.net,3,0,3,0,0,0,0,0
uk.rtyur.com,0,0,0,0,0,0,0,0
cmgdr.sarkie.net,0,0,0,0,0,0,0,0

Still need help...

help me add a header line under each one to easier reference, also I could not get a separate domain.txt file when content is found.

I was expecting something like
sark-usa.rich.net.txt

In that text file I would have

rtre100CLIP.rich.net. IN CNAME CPYIP.dcf.gis.sarkie.com.
gtre10wrLIP.rich.net. IN CNAME SIL101CLIP.dcf.gis.sarkie.com.
gtred1d0LIP.rich.net. IN CNAME SL102CLIP.dcf.gis.sarkie.com.

Thanks


Code


	

(This post was edited by richsark on Jun 16, 2009, 9:09 AM)


richsark
User

Jun 16, 2009, 9:10 AM

Post #3 of 16 (1536 views)
Re: [richsark] Modify perl script with report and count [In reply to] Can't Post

Hello,

Any takers?

I would like some help please. :)


KevinR
Veteran


Jun 16, 2009, 10:08 AM

Post #4 of 16 (1529 views)
Re: [richsark] Modify perl script with report and count [In reply to] Can't Post

I think if you keep plugging away at the problem you will solve it.
-------------------------------------------------


richsark
User

Jun 16, 2009, 10:27 AM

Post #5 of 16 (1528 views)
Re: [KevinR] Modify perl script with report and count [In reply to] Can't Post

Hi Kevin, Belive me, I have been plugging at it. If I had unlimited time, I possiably could :)

Can you help me figure this out please?

Thanks


richsark
User

Jun 16, 2009, 10:46 AM

Post #6 of 16 (1524 views)
Re: [richsark] Modify perl script with report and count [In reply to] Can't Post

Hi,

How about this for geting me the .txt for each domain that contains content:


Code
   foreach my $filename (<*.txt>) {   
next if $filename eq 'list.txt';
}




Code
   

#!perl -w
my @revlist = `./exportdomain.exe -u 123 -p 123 -o srs`;
shift @revlist;
my $report = "";
my @domains;
my @includes;
foreach(@revlist) {
next unless /(.*?),(.*)$/;
my $domain_name = $1;
push @domains, $domain_name;

print "Checking $domain_name\n";
my $txt = `./grabzoneext.exe -u 111 -p 111 -n $domain_name -o srs 2>&1`;
$txt =~ s/[\r\n]+/\n/gs;
my $prefix = ($txt =~ /ParameterName=Prefix[^\r\n]+?[\r\n]+(.*?)(?:OptionType|ParameterName|$)/si) ? $1 : 0;
my $postfix = ($txt =~ /ParameterName=Postfix[^\r\n]+?[\r\n]+(.*?)(?:OptionType|ParameterName|$)/si) ? $1 : 0;
my $include = ($txt =~ /\$INCLUDE\s*([^\r\n]+?)[\r\n]/si) ? $1 : 0;

# if you don't want to print domains without prefix or postfix uncomment the next line
# next unless $prefix || $postfix;

$report .= (join",",$domain_name,map{scalar(()=$txt=~/\s+IN\s+$_.*/g)}(qr/./,qr/A/,qr#CNAME#,qr#MX#,qr#TXT#,qr#SRV#,qr#PTR#,qr#OTHER#))."\n";
foreach my $domain_name (<*.txt>) {
next if $domain_name eq '$domain_name.txt';

push @includes, [$domain_name, $include] if $include;
}

open(my $out, ">domain-inspection-6-2-09.txt") or die "Could not open output: $!\n";
print $out "Summary -- domains found = ".scalar(@domains);
print $report;
print $out "\n\nSummary -- \$INCLUDEs:\n";
print $out "\$INCLUDE ".$_->[1]." found in domain ".$_->[0]."\n" foreach (@includes);
print $out "\nFull Report:\n";
print $out "domain,#records,#A,#CNAME,#MX,#TXT,#SRV,#PTR,#OTHER\n";
print $out $report;

close($out);



(This post was edited by richsark on Jun 16, 2009, 10:51 AM)


KevinR
Veteran


Jun 16, 2009, 11:18 AM

Post #7 of 16 (1518 views)
Re: [richsark] Modify perl script with report and count [In reply to] Can't Post

THis might work if you correct the code:


Code
foreach my $domain_name (<*.txt>) {   
next if $domain_name eq '$domain_name.txt';
push @includes, [$domain_name, $include] if $include;
}


You need double-quotes around $domain_name.txt instead of single-quotes which kills the variable interpolation.
-------------------------------------------------


richsark
User

Jun 16, 2009, 11:46 AM

Post #8 of 16 (1514 views)
Re: [KevinR] Modify perl script with report and count [In reply to] Can't Post

Hello Kevin,
I added this, It runs, but no txt files :(


Code
$report .= (join",",$domain_name,map{scalar(()=$txt=~/\s+IN\s+$_.*/g)}(qr/./,qr/A/,qr#NS#,qr#CNAME#,qr#MX#,qr#TXT#,qr#SRV#,qr#PTR#,qr#OTHER#))."\n"; 
foreach my $domain_name (<*.txt>) {
next if $domain_name eq "$domain_name.txt";
push @includes, [$domain_name, $include] if $include;
}}


Did I not put it in the right place?


(This post was edited by richsark on Jun 16, 2009, 1:06 PM)


KevinR
Veteran


Jun 16, 2009, 3:25 PM

Post #9 of 16 (1508 views)
Re: [richsark] Modify perl script with report and count [In reply to] Can't Post

Rich,

I really don't know if you put it in the right place. I don't really understand what you are even trying to do, and judging by the lack of replies from others I assume nobody else does either.
-------------------------------------------------


richsark
User

Jun 16, 2009, 4:05 PM

Post #10 of 16 (1503 views)
Re: [KevinR] Modify perl script with report and count [In reply to] Can't Post

Ok, I can provide additional information, but if anyone does not understand please let me know.

Its quite simple.

The script does a whole bunch of stuff which works as it. I want to clear the reports portion of the script and have it do something else.

I have 1,000's of domains. Inside each domain contains the words Pre/Post fix just like the scripts reads. If that part it triggered, I want a few things to happen

1. Summy of how many domains found ( already in place)
2.(need this) Create a report.txt with a header on top of each domain like so:

rich.sark.net

domain, rich.sark.net
#records,#A,#CNAME,#MX,#TXT,#SRV,#PTR,#OTHER
3,0,3,0,0,0,0,0

3. (need this)Then another part where the script creates a text file of each domain found from above: for example rich.sark.net.txt
When I open that file, it should correlate with the output from step 2.

Like so ( as an example from rich.sark.net.txt):
rtre100CLIP.rich.net. IN CNAME CPYIP.dcf.gis.sarkie.com.
gtre10wrLIP.rich.net. IN CNAME SIL101CLIP.dcf.gis.sarkie.com.

I hope this is more clearer. I have tried to play with the code as you all can see, but Its beyond my skill set.

I require help please


KevinR
Veteran


Jun 16, 2009, 7:03 PM

Post #11 of 16 (1498 views)
Re: [richsark] Modify perl script with report and count [In reply to] Can't Post

There is a problem here:


Code
        foreach my $domain_name (<*.txt>) {     
next if $domain_name eq "$domain_name.txt";
push @includes, [$domain_name, $include] if $include;


You are declaring $domain_name with "my" in the above loop but you have declared $domain_name earlier in the same scope so any value it had before the loop is gone. Maybe you should use a different name for the scalar you are assigning the results of the glob to and see if that helsp.
-------------------------------------------------


richsark
User

Jun 17, 2009, 3:18 AM

Post #12 of 16 (1492 views)
Re: [KevinR] Modify perl script with report and count [In reply to] Can't Post

Hello Kevin,

So I need to pick another name for this segment

foreach my $domain_name (<*.txt>) {
next if $domain_name eq "$domain_name.txt";
push @includes, [$domain_name, $include] if $include;

so, your saying it could work like this?


Code
foreach my $domain_output (<*.txt>) {      
next if $domain_output eq "$domain_output.txt";
push @includes, [$domain_output, $include] if $include;


Where in my code would I place this?

Could you help me with my other issues?


KevinR
Veteran


Jun 17, 2009, 10:14 AM

Post #13 of 16 (1480 views)
Re: [richsark] Modify perl script with report and count [In reply to] Can't Post

Rich,

If I get time and can comprehend your requirements I will try and help later today.
-------------------------------------------------


richsark
User

Jun 17, 2009, 10:59 AM

Post #14 of 16 (1477 views)
Re: [KevinR] Modify perl script with report and count [In reply to] Can't Post

Thanks Kevin, look forward !


KevinR
Veteran


Jun 18, 2009, 3:08 PM

Post #15 of 16 (1469 views)
Re: [richsark] Modify perl script with report and count [In reply to] Can't Post

Rich,

Sorry but for some reason what you're attempting is just not sinking in with me. I don't understand your requirements.
-------------------------------------------------


richsark
User

Jun 18, 2009, 8:40 PM

Post #16 of 16 (1467 views)
Re: [KevinR] Modify perl script with report and count [In reply to] Can't Post

HI Kevin, dont worry.. thanks for trying anyway

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives