<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
# Author  Robert.Binkley@fnis.com
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-&gt;{$a}[0] &lt;=&gt; $MySQLColOrder-&gt;{$b}[0]}
                    keys  %{$MySQLColOrder}
                   ) {
    $MyHdrLine .= q["] . $MySQLColOrder-&gt;{$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&lt;Y/N&gt;?:];

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 = &lt;STDIN&gt;);
        $MyResp1 = q[1] if ( $MyResp1 eq q[] );
        $MyResp1 =~ s/\s+//g;
        if ( $MyResp1 !~ /[1-3]/ ) {
            printf "Expecting 1, 2 or 3, but got &lt;%s&gt;\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 = &lt;STDIN&gt; );
        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 = &lt;STDIN&gt; );
        $MyResp4 = q[y] if ( $MyResp4 eq q[] );
        if ( $MyResp4 !~ /[yn]/i ) {
            printf "Expecting either a Y or N, but you entered &lt;%s&gt;\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[&lt;] . $MyFileIn) || die "Unable to open input: $!";
        $MyPrtBuf = q[];
        INPUTTP1: while (&lt;MYFILEIN&gt;) {
            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-&gt;[4],
                                            $TimeInfo-&gt;[3],
                                            ++$MyCnt;

             } until ( ! -e $MyCSVFile1 );

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

            open(MYCSVFILE1, q[&gt;] . $MyCSVFile1) || die "Unable to open output $MyCSVFile1: $!";
            open(MYCSVFILE2, q[&gt;] . $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-&gt;{$MyWrkKey} or
                                 ! $MySQLColOrder-&gt;{$MyWrkKey}[0]
                         );
                $MyWorka[$MySQLColOrder-&gt;{$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-&gt;[4],
                                $TimeInfo-&gt;[3],
                                ++$MyCnt;

         } until ( ! -e $MyCSVFile1 );

         $MyCSVFile2 = $MyWrkOutputLoc . sprintf "sn_%s.%02d%02d%02d.02.csv",
                                $MyResp2Wrk,
                                $TimeInfo-&gt;[4],
                                $TimeInfo-&gt;[3],
                                $MyCnt;
        open(MYCSVFILE1, q[&gt;] . $MyCSVFile1) || die "Unable to open output $MyCSVFile1: $!";
        open(MYCSVFILE2, q[&gt;] . $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-&gt;{$MyWrkKey} or
                                 ! $MySQLColOrder-&gt;{$MyWrkKey}[0]
                         );
                $MyWorka[$MySQLColOrder-&gt;{$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 =&gt; YearModulo
#  10 =&gt; Time used in calculations
#
    my $MyPointInTime = time - $diff;
    $MyPointInTime = $MyUseTime if ( defined $MyUseTime );
    @{$TimeInfo} = localtime( $MyPointInTime );
    $TimeInfo-&gt;[4]++;
    $TimeInfo-&gt;[9] = $TimeInfo-&gt;[5] % 100; # Year Modulo, last two digits of year
    $TimeInfo-&gt;[10] = $MyPointInTime;

    $diff = 0;

 }  # end of get_time

sub init_array {
    my( $MyWorka ) = @_;
    my $MyWrkIdx;
    $MyWorka-&gt;[0] = 0;
    for( $MyWrkIdx = 1;$MyWrkIdx&lt;18;$MyWrkIdx++) {
        $MyWorka-&gt;[$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&lt;serial number&gt;


</pre></body></html>