Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Picking up data in a list

Status
Not open for further replies.

lhg1

IS-IT--Management
Mar 29, 2005
134
DK
Hi

Using only Shell sh scripting

I need to get the QUE from 3 adapters. And it gives me the information as shown below. It is not always that there is a que, but when there is one it is the one below the adapter name.

I have an output from a comman that looks something like this. (In reality its longer, but this is 3 "adapters")
Code:
Adapter_SB_SB_CRM_IVR_3 (SiebelAdapter Version 4.2.1 build43 on host "abcrm15") 
        replyTo = Adapter_SB_SB_CRM_IVR_3
        transactions = basic
        CADK = 4.2i (4)
        java.version = 1.2.2
        java.vendor = Sun Microsystems Inc.
        java.compiler = symcjit
        os.name = Windows NT
        os.arch = x86
        os.version = 5.0
        user.language = da
        file.encoding = Cp1252
        startTime = Tue Feb 26 00:00:09 CET 2008
        totalMemory = 3354616
        [b]queueLength = 0[/b]
Adapter_NDOU_Oracle_I_CRM_3 (oracle Version 4.0.4 052802 on host "elwood.dmt.dk") 
        replyTo = Adapter_NDOU_Oracle_I_CRM_3
        dbVendor = oracle
        transactions = basic
        dbVersion = 8i
        CADK = 4.2i (4)
        java.version = 1.2.2.11
        java.vendor = Hewlett-Packard Co.
        java.compiler = 
        os.name = HP-UX
        os.arch = PA_RISC
        os.version = B.11.11
        user.language = en
        file.encoding = 8859_1
        startTime = Thu Feb 14 02:52:18 CET 2008
        totalMemory = 21553152
Adapter_RKI_RKI_C_CRM_3 (CRMRKIAdapter 4.0 on host "elwood.dmt.dk") 
        replyTo = Adapter_RKI_RKI_C_CRM_3
        transactions = basic
        CADK = 4.2i (4)
        java.version = 1.2.2.11
        java.vendor = Hewlett-Packard Co.
        java.compiler = 
        os.name = HP-UX
        os.arch = PA_RISC
        os.version = B.11.11
        user.language = en
        file.encoding = 8859_1
        startTime = Mon Feb 04 03:58:22 CET 2008
        totalMemory = 4980736
        [b]queueLength = 10[/b]


The end result of the script using the example data should be something like this.

Adapter_SB_SB_CRM_IVR_3 0
Adapter_NDOU_Oracle_I_CRM_3 null (there is no que)
Adapter_RKI_RKI_C_CRM_3 10

The trick is that I have to log if the que is above xx.

Hope some one can help

/Lhg
 
Whenever I see something like "Using only Shell sh scripting", it sounds like a school assignment. If this was a work project, I would think you wouldn't care which shell was used.

What have you tried so far?
 
He he - no its not a school project. It is a new product that my company has chosen. And the is has to work on defrent platforms, where shell is a bretty wide spred and always the same place.

What have I tryed before, I'we made the script in perl.
Code:
Get_Output();
Get_queueLength_count();
Action($Adapter);

#----------------------------------------------------------
#----------------------------------------------------------
sub Action
{ my $In = shift (@_);

if (($AdapterHash{$In} eq "") and ($In ne "alle"))
{print "0\n";
 exit;
};

        if ($In eq "alle")
        {       foreach $k (keys %AdapterHash)
                {print " [$AdapterHash{$k}] \t $k\n";}
        }
        else {print "$AdapterHash{$In}\n";}
}

#----------------------------------------------------------
#----------------------------------------------------------
sub Get_queueLength_count
{ $TmpAdapter = 0;
     foreach $line (@Output)
     { chomp $line;
        if ($line =~ /^Adapter/)
        {  my @Tmp = split /\s/, $line; # line looks like this: Adapter_RKI_RKI_C_CRM_Prod (CRMRkiAdapter 4.0 on host "crm1.dmt.dk")
           $TmpAdapter = "$Tmp[0]"; # Adaptername
        }
        elsif ($line =~ /^\s+queueLength/)
        {  my @Tmp = split /queueLength\s=\s/, $line;
           if (exists($AdapterHash{$TmpAdapter}))
           { $AdapterHash{$TmpAdapter} += $Tmp[1];}
           else
           { $AdapterHash{$TmpAdapter} = $Tmp[1];}
        }
     }#foreach $line (@Output)
}#sub Get_queueLength_count

#----------------------------------------------------------
#----------------------------------------------------------
sub Get_Output

{ chomp (@Output = `/opt/active41/bin/adapter_ping  -info Broker_CRM_3\@smrtwebm:6749`);}


I just cant seem to figure out how to catch the que for the adapter in a differet line.

/Lhg
 
A starting point:
Code:
awk '
/^Adapter/{if(NR>1)print x;x=$1}
/queueLength/{x=x" "$NF}
END{print x}
' /path/to/input > output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

I assumed that the Adapter names are unique.
I think your logic is off, you want to add a hash entry when you see the NEXT adapter, and then flush the last one at the end of the file.


#----------------------------------------------------------
#----------------------------------------------------------
sub Action
{ my $In = shift (@_);

foreach $k (keys %AdapterHash) {
{print " $k [$AdapterHash{$k}] \t $k\n";}
}
}

#----------------------------------------------------------
#----------------------------------------------------------
sub Get_queueLength_count
{
my $ql = 0;
$TmpAdapter = 0;
foreach $line (@Output)
{ chomp $line;
if ($line =~ /^Adapter/) {
{ my @Tmp = split /\s/, $line; # line looks like this: Adapter_RKI_RKI_C_CRM_Prod (CRMRkiAdapter 4.0 on host "crm1.dmt.dk")
if ($. != 1) {
$AdapterHash{$LastAdapterName} = $ql;
}
$LastAdapterName = "$Tmp[0]"; # Adaptername
$ql = "null";
next;

}
}
elsif ($line =~ /^\s+queueLength/)
{ my @Tmp = split /queueLength\s=\s/, $line;
$ql = $Tmp[1];
}
}#foreach $line (@Output)
$AdapterHash{$LastAdapterName} = $ql;
}#sub Get_queueLength_count
 
What about

grep -e Adap -e que yourfile | paste - -

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Nice idea mrn, but it doesn't cater for the missing queueLength in some cases.

I know it's not exactly sh as the question asks, but awk should be fairly ubiquitous, so perhaps this would do the trick:

Code:
awk '/^Adap/ { if (a!="") print a,q; a=$1 ;q="null"} /queueLength/ { q=$NF } END { print a,q }' inputfile

Annihilannic.
 
Anni, isn't your suggestion the same as mine (3 Mar 08 3:12) ? ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top