Need help with writing a perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with writing a perl script
# 1  
Old 11-18-2008
Need help with writing a perl script

Hi all!

I have to write a perl script that gets trashholds from a file and match them with an output of a command.

The trashhold file looks like this:

Code:
"pl-it_prod.GW.Sync.reply.*"    "500"   "-1"    ""      ""
"pl-it_prod.A.*"        "100"   "-1"    ""      ""
"application.log"       "50"    "-1"    ""      ""
"eai.log.process.*"     "50"    "-1"    ""      ""
"pl-it_prod.S.*"        "10"    "-2"    ""      ""
"pl-it_prod.P.*"        "10"    "-2"    ""      ""
"pl-it_prod.GW.>"       "10"    "-2"    ""      ""
"pl-it_prod.*.GW.Async.Reply.JMS"       "10"    "-1"    ""      ""

The first filed is the queue name (or part of it), the second filed is the trashold of the queue and the third is the trashold of the number of listeners handling this queue.
When there is a "-" (minus) that meens that the trashold should be checked backwords (less than the trashold...).

The commnad that gives the real state of the queues return an output like this:
Code:
application.log 0       2
application.log.converter       0       0
eai.log.process.activity        0       2
eai.log.process.data    0       20
eai_inspection.start_test       0       1
pl-it_prod.A.EngSystem.V.CD     0       1
pl-it_prod.A.EngSystem.V.CD.EAI_Eng-BWEAIEng-1.DynamicMain      0       1
pl-it_prod.A.EngSystem.V.CD.EAI_Eng-BWEAIEng-1.DynamicMain.Reply        0       1
pl-it_prod.A.EngSystem.V.CD.EAI_Eng-BWEAIEng-2.DynamicMain      0       1
pl-it_prod.A.EngSystem.V.CD.EAI_Eng-BWEAIEng-2.DynamicMain.Reply        0       1
pl-it_prod.A.Orchest.V.CD       0       1
pl-it_prod.A.Orchest.V.CD.Orchest-BWOrch1-1.DynamicMain 0       1
pl-it_prod.A.Orchest.V.CD.Orchest-BWOrch1-1.DynamicMain.Reply   0       1
pl-it_prod.A.Orchest.V.CD.Orchest-BWOrch1-2.DynamicMain 0       1
pl-it_prod.A.Orchest.V.CD.Orchest-BWOrch1-2.DynamicMain.Reply   0       1
pl-it_prod.A.ShavitTuxedo.V.CD  0       1
pl-it_prod.A.ShavitTuxedo.V.CD.ShavitTuxedo-BWTux-1.DynamicMain 0       1
pl-it_prod.A.ShavitTuxedo.V.CD.ShavitTuxedo-BWTux-1.DynamicMain.Reply   0       1
pl-it_prod.A.ShavitTuxedo.V.CD.ShavitTuxedo-BWTux-2.DynamicMain 0       1
pl-it_prod.A.ShavitTuxedo.V.CD.ShavitTuxedo-BWTux-2.DynamicMain.Reply   0       1
pl-it_prod.AD.LDAP.V.CD.LDAPUserAuthGroups      0       4
pl-it_prod.AD.LDAP.V.CD.LDAP_ADInetOrgPerson    0       4
pl-it_prod.AD.LDAP.V.CD.LDAP_Bind       0       4
pl-it_prod.AD.LDAP.V.CD.LDAP_Groups     0       2
pl-it_prod.AD.LDAP.V.CD.LDAP_InetOrgPerson      0       2
pl-it_prod.AD.LDAP.V.CD.LDAP_Workstation        0       2
pl-it_prod.Columbus.Columbus-BWColumbus-1.admin 0       1
pl-it_prod.EAI_Eng.EAI_Eng-BWEAIEng-1.admin     0       1
pl-it_prod.EAI_Eng.EAI_Eng-BWEAIEng-2.admin     0       1
pl-it_prod.GW.Async     0       2
pl-it_prod.GW.Publish   0       2
pl-it_prod.GW.Sync      0       2
pl-it_prod.GW.Sync.reply.SCPROD.Upd_Soc_List    0       1
pl-it_prod.Gateways-B2B.GW.Async.Reply.JMS      0       2
pl-it_prod.Gateways-NPG.GW.Async.Reply.JMS      0       2
pl-it_prod.Gateways-Pele.GW.Async.Reply.JMS     0       2
pl-it_prod.Gateways.GW.Async.Reply.JMS  0       2
pl-it_prod.LDAP.LDAP-BWLDAP-1.admin     0       1
pl-it_prod.LDAP.LDAP-BWLDAP-2.admin     0       1
pl-it_prod.LDAP.adldap.LDAP-AdActiveDir-10.exit 0       1
pl-it_prod.LDAP.adldap.LDAP-AdActiveDir-11.exit 0       1
pl-it_prod.LDAP.adldap.LDAP-AdActiveDir-20.exit 0       1
pl-it_prod.LDAP.adldap.LDAP-AdActiveDir-21.exit 0       1
pl-it_prod.LDAP.adldap.LDAP-AdLDAP-1.exit       0       1
pl-it_prod.LDAP.adldap.LDAP-AdLDAP-2.exit       0       1
pl-it_prod.LoadTester.End       0       1
pl-it_prod.LoadTester.Test.End  0       1
pl-it_prod.MaofDB.MaofDB-BWMaof-1.admin 0       1
pl-it_prod.MaofDB.MaofDB-BWMaof-2.admin 0       1
pl-it_prod.NPG.NPG-BWNPG-1.admin        0       1
pl-it_prod.NPG.NPG-BWNPG-2.admin        0       1
pl-it_prod.Orchest.Orchest-BWOrch1-1.admin      0       1
pl-it_prod.Orchest.Orchest-BWOrch1-2.admin      0       1
pl-it_prod.P.Archive.V.CD       0       2
pl-it_prod.P.Columbus.V.CD      0       2
pl-it_prod.P.EngSystem.V.CD     0       2
pl-it_prod.P.LDAP.V.CD  0       2
pl-it_prod.P.MaofDB.V.CD        0       2
pl-it_prod.P.NPG.V.CD   0       2
pl-it_prod.P.Orchest.V.CD       0       2
pl-it_prod.P.PTL.V.CD   0       2
pl-it_prod.P.ShavitTuxedo.V.CD  0       2
pl-it_prod.S.Archive.V.CD       0       2
pl-it_prod.S.Columbus.V.CD      0       2
pl-it_prod.S.EngSystem.V.CD     0       2
pl-it_prod.S.LDAP.V.CD  0       2
pl-it_prod.S.MaofDB.V.CD        0       2
pl-it_prod.S.NPG.V.CD   0       2
pl-it_prod.S.Orchest.V.CD       0       2
pl-it_prod.S.PTL.V.CD   0       2
pl-it_prod.S.ShavitTuxedo.V.CD  0       2
pl.processes.Add_User_Soc-Callback.in   0       0
pl.processes.Close_User_Soc-Callback.in 0       0
stam    0       11
umts.processes.Add_User_Soc-Callback.in 0       0
umts.processes.Close_User_Soc-Callback.in       0       0


So far my perl script looks like this and i'm stuck:
Code:
#!/usr/bin/perl



here load queue policy to hash


open(QUEUE, "/users/tibprod/scripts/ShowQueues_leaiprod.sh|") or die "failed to get queues stats" ;
foreach $line (<QUEUE>) {
    ($que_name,$que_thresh,$que_listen) = split $line;
    foreach $que_thresh (keys %QueLim) {
        if ( $que_name =~ /${que_thresh} ) {
            check the thresh
        }

    }


}

Hope that everything was explained clearly...
Please help me so i could get it done!

Thank you so much!!! SmilieSmilieSmilie

Eliraz.
# 2  
Old 11-18-2008
Please post an example of the desired output given the sample data.
# 3  
Old 11-18-2008
Quote:
Originally Posted by radoulov
Please post an example of the desired output given the sample data.
oops i forgot...

whenever the trashhold of the real queues is larger\smaller than the trashold then i need to print to the screen "ERROR THE TRASHOLD OF QUEUE $QUEUENAME IS $TRASHOLD"
# 4  
Old 11-18-2008
Something to begin with (it will print any mismatch):

Code:
#! /usr/bin/env perl


use warnings;
use strict;

my ($Thresholds_f, $Queue) = 
  ('/path/to/thresholds_file', '/users/tibprod/scripts/ShowQueues_leaiprod.sh|');
my %Thresholds_h;

open TH, '<', $Thresholds_f  or die "$Thresholds_f: $!\n";
  
while (<TH>) {
  tr/"//d;
  my @Fields = split /\s+/;
  $Thresholds_h{$Fields[0]} = [@Fields[1,2]];
  }

close TH;  

open QUEUE, '<', $Queue or die "$Queue: $!\n";

while (<QUEUE>) {
  my $Flag = 0;
  my @Fields = split /\s+/;
  while (my($Key, $Ref) = each %Thresholds_h) {
    my @Values = @$Ref;
    if ($Fields[0] =~ /^$Key$/) {
      print "\nChecking queue: $Fields[0] ... ";
      if ($Fields[1] != $Values[0]) {
        print "\n\n\t--> queue threshold mismatch: \n\n\tcurrent status: ",
        $Fields[1], "\n\tthreshold:      ", $Values[0], "\n";
        $Flag++
        }
      if ($Fields[2] != $Values[1]) {
         print "\n\t--> listeners threshold mismatch: \n\n\tcurrent status: ",
        $Fields[2], "\n\tthreshold:      ", $Values[1], "\n";
        $Flag++
        }
      print "OK\n\n" unless $Flag;    
      }
    }
  }  
  
close QUEUE;


Last edited by radoulov; 11-18-2008 at 01:00 PM..
# 5  
Old 11-18-2008
Quote:
Originally Posted by radoulov
Something to begin with (it will print any mismatch):

Code:
#! /usr/bin/env perl


use warnings;
use strict;

my ($Thresholds_f, $Queue) = 
  ('/path/to/thresholds_file', '/users/tibprod/scripts/ShowQueues_leaiprod.sh|');
my %Thresholds_h;

open TH, '<', $Thresholds_f  or die "$Thresholds_f: $!\n";
  
while (<TH>) {
  tr/"//d;
  my @Fields = split /\s+/;
  $Thresholds_h{$Fields[0]} = [@Fields[1,2]];
  }

close TH;  

open QUEUE, '<', $Queue or die "$Queue: $!\n";

while (<QUEUE>) {
  my $Flag = 0;
  my @Fields = split /\s+/;
  while (my($Key, $Ref) = each %Thresholds_h) {
    my @Values = @$Ref;
    if ($Fields[0] =~ /^$Key$/) {
      print "\nChecking queue: $Fields[0] ... ";
      if ($Fields[1] != $Values[0]) {
        print "\n\n\t--> queue threshold mismatch: \n\n\tcurrent status: ",
        $Fields[1], "\n\tthreshold:      ", $Values[0], "\n";
        $Flag++
        }
      if ($Fields[2] != $Values[1]) {
         print "\n\t--> listeners threshold mismatch: \n\n\tcurrent status: ",
        $Fields[2], "\n\tthreshold:      ", $Values[1], "\n";
        $Flag++
        }
      print "OK\n\n" unless $Flag;    
      }
    }
  }  
  
close QUEUE;

WOW! that's look like you put a lot of work in to it!
actually i'm not in the office right now but i'll check this and let you know first thing!

thanks alot m8!
# 6  
Old 11-19-2008
Well I've checked the script and puted the wright pathes in it...

It's now looks like this:
Code:
#! /usr/bin/env perl


use warnings;
use strict;

my ($Thresholds_f, $Queue) =
  ('/users/tibprod/scripts/EMS_Queue_List_leaiprod.lst', '/users/tibprod/scripts/ShowQueues_leaiprod.sh');
my %Thresholds_h;

open TH, '<', $Thresholds_f  or die "$Thresholds_f: $!\n";

while (<TH>) {
  tr/"//d;
  my @Fields = split /\s+/;
  $Thresholds_h{$Fields[0]} = [@Fields[1,2]];
  }

close TH;

open QUEUE, '<', $Queue or die "$Queue: $!\n";

while (<QUEUE>) {
  my $Flag = 0;
  my @Fields = split /\s+/;
  while (my($Key, $Ref) = each %Thresholds_h) {
    my @Values = @$Ref;
    if ($Fields[0] =~ /^$Key$/) {
      print "\nChecking queue: $Fields[0] ... ";
      if ($Fields[1] != $Values[0]) {
        print "\n\n\t--> queue threshold mismatch: \n\n\tcurrent status: ",
        $Fields[1], "\n\tthreshold:      ", $Values[0], "\n";
        $Flag++
        }
      if ($Fields[2] != $Values[1]) {
         print "\n\t--> listeners threshold mismatch: \n\n\tcurrent status: ",
        $Fields[2], "\n\tthreshold:      ", $Values[1], "\n";
        $Flag++
        }
      print "OK\n\n" unless $Flag;
      }
    }
  }

close QUEUE;

but when i'm running it i'm getting:
Code:
[root@leaiprod1 scripts]# ./temp2.pl
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 5.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 5.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 5.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 5.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 5.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 5.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 5.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 5.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 8.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 8.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 8.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 8.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 8.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 8.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 8.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 8.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 10.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 10.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 10.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 10.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 10.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 10.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 10.
Use of uninitialized value in pattern match (m//) at ./temp2.pl line 28, <QUEUE> line 10.

What seems to be the problem?

Thanks again!
# 7  
Old 11-19-2008
It seams the ShowQueues_leaiprod.sh sometimes returns an output different from the one you posted. You may need to add an error checking there.

This should be a workaround:

change:

Code:
while (<QUEUE>) {
  my $Flag = 0;

to:

Code:
while (<QUEUE>) {
  next unless /\w+\s+/;
  my $Flag = 0;

I'm sure the checking logic should be modified, but I'll need more details to understand how.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Writing xml from excel sheet .xls using perl script

Hi all. I am working on the below requirement of generating .xml file from .xls file which i have , can someone please help me or in writing the perl script for the same: The xls file format is as below which has two columns and number of rows are not fixed: Fixlet Name ... (12 Replies)
Discussion started by: omkar.jadhav
12 Replies

2. Shell Programming and Scripting

Need help in writing perl script

Hi, I am new to perl. I am trying to write a small perl script for search and replace in a file : ======================================================== #!/usr/bin/perl my $searchStr = "register_inst\.write_t\("; my $replaceStr = "model\.fc_block\."; open(FILE,"temp.sv") ||... (2 Replies)
Discussion started by: chettyravi
2 Replies

3. UNIX for Dummies Questions & Answers

Writing an HTML file in perl

I'm writing a perl script that writes an html file. use Tie::File; my ($dir) = @ARGV; open (HTML,">","$dir/file.html") || die $!; #-----Building HTML file--------------------------- print HTML "<!DOCTYPE html> <html> <head> <title>Output</title> <link... (3 Replies)
Discussion started by: jrymer
3 Replies

4. Shell Programming and Scripting

Perl script for Calling a function and writing all its contents to a file

I have a function which does awk proceessing sub mergeDescription { system (q@awk -F'~' ' NR == FNR { A = $1 B = $2 C = $0 next } { n = split ( C, V, "~" ) if... (3 Replies)
Discussion started by: crypto87
3 Replies

5. Programming

REQUIRE HELP IN WRITING A PERL SCRIPT

Hi everyone I am a beginner in perl and I am trying to write a perl script. Basically I want to separate gene entries from phenotype entries in a text file which contains huge number of records and copy them in a separate file. The gene entries will have * symbol after the line FIELD TI. A... (7 Replies)
Discussion started by: kaav06
7 Replies

6. Shell Programming and Scripting

Writing a Perl Script that processes multiple files

I want to write a Perl script that manipulates multiple files. In the directory, I have files 250.*chr$.ped where * is from 1 to 1000 and $ is from 1-22 for a total of 22 x 10,000 = 22,000 files. I want to write a script that only manipulates files 250.1chr*.ped where * is from 1 to 22.... (10 Replies)
Discussion started by: evelibertine
10 Replies

7. UNIX for Dummies Questions & Answers

help in writing perl module

Hi i have written a perl script which was then converted to perl module by me. it works as expected. but i have to put it on many servers so i want to build a package for it. i dont know how to do that. just to check i copied perl module in "lib" directory which is working. ( directly copied... (1 Reply)
Discussion started by: zedex
1 Replies

8. Shell Programming and Scripting

help for a perl script - writing to a data file

Hi, Here is my problem.. i have 2 files (file1, file2).. i have wrote the last two lines and first 4 lines of "file2" into two different variables .. say.. my $firstrec = `head -4 $file2`; my $lastrec = `tail -2 $file2`; and i write the rest of the file2 to a tmpfile and cat it with head... (2 Replies)
Discussion started by: meghana
2 Replies

9. UNIX for Dummies Questions & Answers

Perl Unix Script Writing

Hi Folks, I posted a few days ago, thanks for the responses. My original question was for renaming files of sort 3p2325294.dgn in a directory containing multiple files. I need to drop the first 2 characters and the last in a unix script using Perl. How does it differ from using the Unix... (1 Reply)
Discussion started by: Dinkster
1 Replies

10. Shell Programming and Scripting

Writing perl module

Hi, I'd like to create perl functions in separate file from my scripts. Does somebody know if it's possible to create and use a perl module without compiling it ? Thanks. (4 Replies)
Discussion started by: jo_aze
4 Replies
Login or Register to Ask a Question