Loading ...
Sorry, an error occurred while loading the content.

Aix script to gather config info using prtconf output csv.

Expand Messages
  • leebinkley
    #!/usr/bin/perl # Author leebinkley@yahoo.com use strict; use warnings; my $diff = 0; my @TI = (); my $TimeInfo = @TI; get_time($TimeInfo); my $MyWrkLoc =
    Message 1 of 5 , Mar 29, 2009
    • 0 Attachment
      #!/usr/bin/perl
      # Author leebinkley@...
      use strict;
      use warnings;

      my $diff = 0;
      my @TI = ();
      my $TimeInfo = \@TI;
      get_time($TimeInfo);

      my $MyWrkLoc = q[C:/CurrWrka/00CommonPerl/00Data/prtconf];
      my $MyWrkOutputLoc = q[c:/tmp/];
      my $MyFileOut = q[];
      my $MyHardCopyFile = q[];
      my $MainLoc = $MyWrkOutputLoc;

      my %MSCO = ( q[hostname] ,[1 , q[Hostname] ],
      q[systemmodel] ,[2 , q[System Model] ],
      q[machineserialnumber] ,[3 , q[Serial Number] ],
      q[processortype] ,[4 , q[Processor Type] ],
      q[numberofprocessors] ,[5 , q[Number Of Processors] ],
      q[processorclockspeed] ,[6 , q[Processor Clock Speed] ],
      q[cputype] ,[7 , q[CPU Type] ],
      q[kerneltype] ,[8 , q[Kernel Type] ],
      q[lparinfo] ,[9 , q[LPAR Info] ],
      q[memorysize] ,[10 , q[Memory Size] ],
      q[goodmemorysize] ,[11 , q[Good Memory Size] ],
      q[totalpagingspace] ,[12 , q[Paging Space] ],
      q[platformfirmwareversion] ,[13 , q[Platform Firmware Level] ],
      q[firmwareversion] ,[14 , q[Firmware Version] ],
      q[ipaddress] ,[15 , q[IP Address] ],
      q[subnetmask] ,[16 , q[Sub Netmask] ],
      q[gateway] ,[17 , q[Gateway] ]
      );
      my $MySQLColOrder = \%MSCO;

      my %MDD = ();
      my $MyDBDtl = \%MDD;
      my $MyHdrLine = q[];
      my $MyPrtKey;
      foreach $MyPrtKey ( sort { $MySQLColOrder->{$a}[0] <=> $MySQLColOrder->{$b}[0]}
      keys %{$MySQLColOrder}
      ) {
      $MyHdrLine .= q["] . $MySQLColOrder->{$MyPrtKey}[1] . q[",];

      }
      $MyHdrLine =~ s/,\s*$//g;
      #printf "MyDbHdrLine:\n%s\n",
      # $MyHdrLine;

      my $MyDisp1 = q[1) Exit, 2) Host Name 3) Serial Nbr: ];
      my $MyDisp2 = q[Please enter Host Name:];
      my $MyDisp3 = q[Please enter Serial Nbr :];
      my $MyDisp4 = q[CSV<Y/N>?:];

      my $MyWrkDisp;
      my $MyResp1;
      my $MyResp2;
      my $MyResp4;

      my $MyFileIn;
      my $MyDataHit;

      my $MyIn = 0;
      my $MyPrtBuf;
      my $MyPrtBufSerialNbr;

      my $MySerialNbrSw;

      OUTER1: while ( 1 ) {
      OUTER2: while ( 1 ) {
      printf "%s",
      $MyDisp1;
      chomp($MyResp1 = <STDIN>);
      $MyResp1 = q[1] if ( $MyResp1 eq q[] );
      $MyResp1 =~ s/\s+//g;
      if ( $MyResp1 !~ /[1-3]/ ) {
      printf "Expecting 1, 2 or 3, but got <%s>\n",
      $MyResp1;
      printf "Please enter correct value.\n";
      next OUTER2;
      }
      last OUTER2;
      } # end of OUTER2
      last OUTER1 if ( $MyResp1 eq q[1] );
      $MyPrtBufSerialNbr = q[];
      $MySerialNbrSw = 1;
      $MyWrkDisp = $MyDisp3;
      if ( $MyResp1 eq q[2] ) {
      $MyWrkDisp = $MyDisp2;
      $MySerialNbrSw = 0;
      }
      OUTER3: while ( 1 ) {
      printf "%s ",
      $MyWrkDisp;
      chomp($MyResp2 = <STDIN> );
      if ( $MyResp2 eq q[] ) {
      printf "Nothing was entered. Must enter something to search for!!\n";
      next OUTER3;
      }
      last OUTER3;
      } # end of OUTER3

      OUTER3A: while ( 1 ) {
      printf "%s ",
      $MyDisp4;
      chomp($MyResp4 = <STDIN> );
      $MyResp4 = q[y] if ( $MyResp4 eq q[] );
      if ( $MyResp4 !~ /[yn]/i ) {
      printf "Expecting either a Y or N, but you entered <%s>\n",
      $MyResp4;
      next OUTER3A;
      }
      last OUTER3A;
      } # end of OUTER3A

      opendir( MYWRKLOC , $MyWrkLoc ) || die "Unable to opendir: $!";
      chdir($MyWrkLoc) || die "Unable to chdir: $!";
      $MyDataHit = 0;
      $MyIn = 0;
      $MyPrtBufSerialNbr = q[];

      OUTER4: while( 1 ) {
      $MyFileIn = readdir(MYWRKLOC);
      last OUTER4 if ( ! defined $MyFileIn );
      next OUTER4 if ( $MyFileIn =~ /^\.{1,2}$/ );
      $MyIn++;
      open(MYFILEIN, q[<] . $MyFileIn) || die "Unable to open input: $!";
      $MyPrtBuf = q[];
      INPUTTP1: while (<MYFILEIN>) {
      s/\t/ /g;
      $MyPrtBuf .= $_;
      if ( $MyDataHit ) {
      last INPUTTP1 if ( /^\s+percent\s+used:/i );
      next INPUTTP1;
      }
      chomp;
      if ( $MyResp1 eq q[3] ) {
      if ( /^machine\s+serial\s+number:/i ) {
      if ( /$MyResp2/i ) {
      $MyDataHit = 1;
      }
      else {
      last INPUTTP1;
      }
      }
      }
      else {
      if ( /^\s+Host\s+Name:/i ) {
      if ( /$MyResp2/i ) {
      $MyDataHit = 1;
      }
      else {
      last INPUTTP1;
      }
      }
      }
      } #end of INPUTTP1
      next OUTER4 if ( ! $MyDataHit );
      if ( $MySerialNbrSw ) {
      $MyPrtBufSerialNbr .= sprintf "%s:" . q[*]x20 . qq[\n]. "%s",
      $MyFileIn,
      $MyPrtBuf;
      $MyDataHit = 0;
      next OUTER4;
      }
      if ( $MyResp4 !~ /y/i ) {

      printf "%s:\n%s",
      $MyFileIn,
      $MyPrtBuf;
      }
      else {
      my $MyCnt = -1;
      my $MyCSVFile1;
      my $MyCSVFile2;
      my $MyWrkFileIn = $MyFileIn;
      $MyWrkFileIn =~ s/\..{3}$//g;
      my $MyResp2Wrk = $MyResp2;
      $MyResp2Wrk =~ s/[\\\/]/_/g if ( $MyResp2Wrk =~ /[\\\/]/ );
      $MyResp2Wrk =~ s/\_{2,}/\_/g;
      do {

      $MyCSVFile1 = $MyWrkOutputLoc . sprintf "hn_%s.%02d%02d%02d.01.csv",
      $MyResp2Wrk,
      $TimeInfo->[4],
      $TimeInfo->[3],
      ++$MyCnt;

      } until ( ! -e $MyCSVFile1 );

      $MyCSVFile2 = $MyWrkOutputLoc . sprintf "hn_%s.%02d%02d%02d.02.csv",
      $MyResp2Wrk,
      $TimeInfo->[4],
      $TimeInfo->[3],
      $MyCnt;

      open(MYCSVFILE1, q[>] . $MyCSVFile1) || die "Unable to open output $MyCSVFile1: $!";
      open(MYCSVFILE2, q[>] . $MyCSVFile2) || die "Unable to open output $MyCSVFile2: $!";
      my $MyWrkFld;
      printf MYCSVFILE1 "%s,%s\n",
      q[prtconf],
      $MyWrkFileIn;
      printf MYCSVFILE2 "%s\n",
      $MyHdrLine;
      my @MyWorka = ();
      my $MyWrkKey;
      my $MyWrkData;
      my $MyWrkIdx;
      init_array( \@MyWorka );

      foreach $MyWrkFld ( split( /\n/, $MyPrtBuf ) ) {
      if ( $MyWrkFld !~ /\:/ ) {
      printf MYCSVFILE1 "%s\n",
      $MyWrkFld;
      next;
      }
      else {
      printf MYCSVFILE1 "%s,\"%s\"\n",
      split(/\s*:\s*/, $MyWrkFld );
      }
      ( $MyWrkKey, $MyWrkData ) = split(/\s*:\s*/, $MyWrkFld );
      $MyWrkKey =~ s/\s+//g;
      $MyWrkKey = lc($MyWrkKey);

      next if ( ! exists $MySQLColOrder->{$MyWrkKey} or
      ! $MySQLColOrder->{$MyWrkKey}[0]
      );
      $MyWorka[$MySQLColOrder->{$MyWrkKey}[0]] = $MyWrkData;
      $MyWorka[0]++;
      } # end of foreach to build csv
      close(MYCSVFILE1);
      printf "Std CSV created:\n %s\n",
      $MyCSVFile1;
      prt_line(\@MyWorka);
      printf "DBLoad CSV created:\n %s\n",
      $MyCSVFile2;
      close(MYCSVFILE2);
      }
      last OUTER4;
      } # end of OUTER4
      closedir(MYWRKLOC);
      if ( ! $MyDataHit ) {
      if ( ! $MySerialNbrSw or $MyPrtBufSerialNbr eq q[] ) {
      printf "*** NO Hits ***\n";
      printf "Searched all prtconf files on ";
      if ( $MyResp1 eq q[3] ) {
      printf "Serial Number "
      }
      else {
      printf "Host Name "
      }
      printf "using pattern: %s\n",
      $MyResp2;
      printf "*** NO Hits ***\n";
      printf "Files: %6d\n",
      $MyIn;
      exit(0);
      }
      }
      next OUTER1 if ( ! $MySerialNbrSw );

      if ( $MyResp4 !~ /y/i ) {

      printf "%s",
      $MyPrtBufSerialNbr;
      }
      else {
      my $MyCnt = 0;
      my $MyCSVFile1;
      my $MyCSVFile2;
      # my $MyWrkFileIn = $MyFileIn;
      # $MyWrkFileIn =~ s/\..{3}$//g;
      my $MyResp2Wrk = $MyResp2;
      $MyResp2Wrk =~ s/[\\\/\*]/_/g if ( $MyResp2Wrk =~ /[\\\/\*]/ );
      $MyResp2Wrk =~ s/\_{2,}/\_/g;
      do {

      $MyCSVFile1 = $MyWrkOutputLoc . sprintf "sn_%s.%02d%02d%02d.01.csv",
      $MyResp2Wrk,
      $TimeInfo->[4],
      $TimeInfo->[3],
      ++$MyCnt;

      } until ( ! -e $MyCSVFile1 );

      $MyCSVFile2 = $MyWrkOutputLoc . sprintf "sn_%s.%02d%02d%02d.02.csv",
      $MyResp2Wrk,
      $TimeInfo->[4],
      $TimeInfo->[3],
      $MyCnt;
      open(MYCSVFILE1, q[>] . $MyCSVFile1) || die "Unable to open output $MyCSVFile1: $!";
      open(MYCSVFILE2, q[>] . $MyCSVFile2) || die "Unable to open output $MyCSVFile2: $!";
      my $MyWrkFld;
      my @MyWorka = ();
      my $MyWrkKey;
      my $MyWrkData;
      my $MyWrkIdx;
      init_array( \@MyWorka );
      my $MyProcSw = 0;

      printf MYCSVFILE2 "%s\n",
      $MyHdrLine;

      foreach $MyWrkFld ( split( /\n/, $MyPrtBufSerialNbr ) ) {
      if ( $MyWrkFld !~ /\:/ ) {
      printf MYCSVFILE1 "%s\n",
      $MyWrkFld;
      }
      else {
      printf MYCSVFILE1 "%s,\"%s\"\n",
      split(/\s*:\s*/, $MyWrkFld );
      if ( $MyWrkFld =~ /\*{4}/ ) {
      if ( $MyWorka[0] ) {
      prt_line( \@MyWorka );
      init_array( \@MyWorka );
      }
      }
      ( $MyWrkKey, $MyWrkData ) = split(/\s*:\s*/, $MyWrkFld );
      $MyWrkKey =~ s/\s+//g;
      $MyWrkKey = lc($MyWrkKey);

      next if ( ! exists $MySQLColOrder->{$MyWrkKey} or
      ! $MySQLColOrder->{$MyWrkKey}[0]
      );
      $MyWorka[$MySQLColOrder->{$MyWrkKey}[0]] = $MyWrkData;
      $MyWorka[0]++;
      }
      } # end of foreach to build csv

      if ( $MyWorka[0] ) {
      prt_line( \@MyWorka );
      init_array( \@MyWorka );
      }

      close(MYCSVFILE1);
      printf "Std CSV created:\n %s\n",
      $MyCSVFile1;
      printf "DBLoad CSV created:\n %s\n",
      $MyCSVFile2;
      close(MYCSVFILE2);
      }

      } # end of main OUTER1

      #
      ##
      ### Start of Subroutines
      ##
      #

      sub get_time {
      my ( $TimeInfo, $MyUseTime ) = @_;
      $diff = 86400 * $diff;
      # 0 1 2 3 4 5 6 7 8
      # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time - $diff);
      # 9 => YearModulo
      # 10 => Time used in calculations
      #
      my $MyPointInTime = time - $diff;
      $MyPointInTime = $MyUseTime if ( defined $MyUseTime );
      @{$TimeInfo} = localtime( $MyPointInTime );
      $TimeInfo->[4]++;
      $TimeInfo->[9] = $TimeInfo->[5] % 100; # Year Modulo, last two digits of year
      $TimeInfo->[10] = $MyPointInTime;

      $diff = 0;

      } # end of get_time

      sub init_array {
      my( $MyWorka ) = @_;
      my $MyWrkIdx;
      $MyWorka->[0] = 0;
      for( $MyWrkIdx = 1;$MyWrkIdx<18;$MyWrkIdx++) {
      $MyWorka->[$MyWrkIdx] = q[];
      }

      } # end of init_array

      sub prt_line {
      my($MyWorka) = @_;
      shift(@{$MyWorka});
      my $MyWrkKey;
      foreach $MyWrkKey ( @{$MyWorka} ) {
      printf MYCSVFILE2 "\"%s\",",
      $MyWrkKey;
      }
      printf MYCSVFILE2 "\n";
      } # end of prt_line

      #
      ##
      ### Start of Subroutines
      ##
      #

      __DATA__
      Hostname System Model Serial Number Processor Type Number Of Processors Processor Clock Speed CPU Type Kernel Type LPAR Info Memory Size Good Memory Size Paging Space Platform Firmware level Firmware Version IP Address Sub Netmask Gateway
      y x y x x x x x x x x y ? ? x x x
      if Host name prints thru 28 on spread sheet (which thru /percent used:/ )
      if serial number then can be multiple, so file name is by sn<serial number>
    • Charles K. Clarkson
      ... [snip] Why are you submitting this? Is it for peer review? CPAN has a script repository if you want to contribute scripts to the perl community. HTH,
      Message 2 of 5 , Mar 31, 2009
      • 0 Attachment
        leebinkley wrote:
        > #!/usr/bin/perl
        [snip]

        Why are you submitting this?

        Is it for peer review?


        CPAN has a script repository if you want to contribute scripts to the
        perl community.


        HTH,

        Charles Clarkson
        --
        Mobile Home Investor
        Free Market Advocate
        Programmer

        Stephenville, TX
        http://www.clarksonenergyhomes.com/wordpress/about/
        http://twitter.com/CharlesClarkson
        +1 (254) 968-8328
      • Robert Binkley
        I submitted this script in the event for aix administrators. so it should go to cpan site ok thanks ... From: Charles K. Clarkson
        Message 3 of 5 , Mar 31, 2009
        • 0 Attachment
          I submitted this script in the event for aix administrators. so it should go to cpan site ok thanks

          --- On Tue, 3/31/09, Charles K. Clarkson <cclarkson@...> wrote:


          From: Charles K. Clarkson <cclarkson@...>
          Subject: Re: [PBML] Aix script to gather config info using prtconf output csv.
          To: perl-beginner@yahoogroups.com
          Date: Tuesday, March 31, 2009, 11:49 AM






          leebinkley wrote:
          > #!/usr/bin/perl
          [snip]

          Why are you submitting this?

          Is it for peer review?

          CPAN has a script repository if you want to contribute scripts to the
          perl community.

          HTH,

          Charles Clarkson
          --
          Mobile Home Investor
          Free Market Advocate
          Programmer

          Stephenville, TX
          http://www.clarkson energyhomes. com/wordpress/ about/
          http://twitter. com/CharlesClark son
          +1 (254) 968-8328
















          [Non-text portions of this message have been removed]
        • merlyn@stonehenge.com
          ... Robert I submitted this script in the event for aix administrators. so it Robert should go to cpan site ok thanks That s not how to put things onto the
          Message 4 of 5 , Mar 31, 2009
          • 0 Attachment
            >>>>> "Robert" == Robert Binkley <leebinkley@...> writes:

            Robert> I submitted this script in the event for aix administrators. so it
            Robert> should go to cpan site ok thanks

            That's not how to put things onto the CPAN.

            Please see http://www.cpan.org/misc/cpan-faq.html

            --
            Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
            <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
            Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
            See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
          • Robert Binkley
            Thanks for the Info awaiting on password     Request to register new user fullname: Robert Lee Binkley Jr   userid: RBINKL     mail: CENSORED homepage:  
            Message 5 of 5 , Mar 31, 2009
            • 0 Attachment
              Thanks for the Info awaiting on password
               
               
              Request to register new user

              fullname: Robert Lee Binkley Jr
                userid: RBINKL
                  mail: CENSORED
              homepage:
                   why:

                  Aix System Administration Scripts Tru64 System Administration
                  Scripts Hpux Script Code All written without needing perl modules


               
               
               
               
               
              --- On Tue, 3/31/09, merlyn@... <merlyn@...> wrote:


              From: merlyn@... <merlyn@...>
              Subject: Re: [PBML] Aix script to gather config info using prtconf output csv.
              To: "Robert Binkley" <leebinkley@...>
              Cc: perl-beginner@yahoogroups.com
              Date: Tuesday, March 31, 2009, 7:32 PM






              >>>>> "Robert" == Robert Binkley <leebinkley@yahoo. com> writes:

              Robert> I submitted this script in the event for aix administrators. so it
              Robert> should go to cpan site ok thanks

              That's not how to put things onto the CPAN.

              Please see http://www.cpan. org/misc/ cpan-faq. html

              --
              Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
              <merlyn@stonehenge. com> <URL:http://www.stonehen ge.com/merlyn/>
              Smalltalk/Perl/ Unix consulting, Technical writing, Comedy, etc. etc.
              See http://methodsandme ssages.vox. com/ for Smalltalk and Seaside discussion















              [Non-text portions of this message have been removed]
            Your message has been successfully submitted and would be delivered to recipients shortly.