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!

Check conditions and display results in a row

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hi folks,

could you help me out on a little problem ?

Here's what I'm trying to do:

Let's say I'd like to check several conditions which can only be "0" and "NOT 0". The results are supposed to be displayed in a row. Like that:

Code:
          |System1  |System2  |
------------------------------|
Archiver1 |Errors   |No Error |
Archiver2 |No Error |No Error |
Archiver3 |No Error |Errors   |

So far no problem because I was able to accomplish this using

Code:
if [ $check1system1 -eq 0 -a check1system2 -eq 0 ];
then
echo "Archiver1 | No Error |No Error |"
fi

if [ $check1system1 -eq 0 -a check1system2 -ne 0 ];
then
echo "Archiver1 | No Error |Errors   |"
fi

and so on ...

In that scenario this leaves me with 12 if clauses (Not good, but still managable ;-) ). But now I'd like to extend the whole thing like this:

Code:
          |System1            |System2            |
          |---------------------------------------|
          |#Errors  |State    |#Errors  |State    |
--------------------------------------------------|
Archiver1 |       0 |Running  |       1 |DOWN     |
Archiver2 |       5 |Running  |       0 |Running  |
Archiver3 |       0 |DOWN     |       8 |Running  |

Problem: If I would use the if clauses structure from above this would become way too complex. Is there an elegant way around this I could use instead ?

Regards
Thomas
 
A starting point:
Code:
awk -F'|' '/^Archiver/{
printf "%-10s|%-9s|%-9s|%-9s|%-9s|\n",$1,($2==0?"No Error":"Errors"),$3,($4==0?"No Error":"Errors"),$5
}' /path/to/input

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top