-1
for i in $(cat HPE_FRAMES_IP); do  ssh Reports@$i showsys | awk '{print $2,$5}' | column -t ; ssh Reports@$i showpd -degraded -failed | awk '{print $1,$2,$3,$5}' ; done | grep -v "MiB" | grep -v "total"
--Name---  Nodes
AN4ZX8401  MXN6232L4X
No PDs listed
----Name-----  Nodes
bga1ZX84-3128  4C17253128
No PDs listed
---Name---  Nodes
ZZ2ZX20841  CZ3741XP9X
No PDs listed
--Name---  Nodes
ZZ2ZX8401  MXN6102C7F
No PDs listed
--Name---  Nodes
ZZ2ZX8402  2MT814A12A
No PDs listed
--Name---  Nodes
CR3ZX8401  2M263601BJ
Id CagePos Type State
175 9:15:0 FC failed
---Name---  Nodes
ZZZZX20841  CZ3741X5K8
Id CagePos Type State
18 4:2:0 SSD degraded
-------Name-------  Nodes
ZZZZX8401_Full_DNA  MXN54823JY
No PDs listed
--Name---  Nodes
ZZZZX8402  MXN6102CAF
No PDs listed
-------Name-------  Nodes
ZZZZX8403_Full_DNA  MXN6192JEW
No PDs listed

following code gives desired output however I need to redirect this output in a CSV file with below format

I want to print output only when there's an actual output which has degraded or failed for showpd & showsys command.

desired output should be:

--Name---,Nodes
CR3ZX8401,2M263601BJ
Id,CagePos,Type,State
175,9:15:0,FC,failed

---Name---,Nodes
ZZZZX20841,CZ3741X5K8
Id,CagePos,Type,State
18,4:2:0,SSD,degraded

Question updated with below

showpd output can have multiple degrraded and failed output in that case printing with -B3 will not do... what if pattern below is output

'---Name---,Nodes 
FM1HP20841,CZ3741X5K8 
Id,CagePos,Type,State 
18,4:2:0,SSD,degraded 
18,4:2:1,SSD,failed 
2

Try this,

for i in $(cat HPE_FRAMES_IP); do ssh Reports@$i showsys | awk '{print $2","$5}' ; ssh Reports@$i showpd -degraded -failed | awk '{print $1","$2","$3","$5}' ; done | grep -v "MiB" | grep -v "total" | egrep -B3 "failed|degraded" | sed 's/---Name/\n---Name/g' > file.csv
  • just wrap the comma with double quotes in awk
  • remove column
  • then do extended grep with the keywords
  • -B3 will print the 3 lines before the matching keyword
  • sed is to add new line before "Name" as expected output
  • I would use printf "%s,%s\n", option in awk. – Archemar Mar 20 at 14:31
  • showpd output can have multiple degrraded and failed output in that case printing with -B3 will not do... what if below is the output pattern below is output '---Name---,Nodes FM1HP20841,CZ3741X5K8 Id,CagePos,Type,State 18,4:2:0,SSD,degraded 18,4:2:1,SSD,failed 18,4:2:6,SSD,degraded` – user3016638 Mar 20 at 17:03
  • @user3016638 can u update the same in question – msp9011 Mar 20 at 18:23
  • Question has been updated – user3016638 Mar 21 at 1:00
  • @msp9011 can you please help me with this – user3016638 Mar 21 at 4:49
0

Grep will help here :

for i in $(cat HPE_FRAMES_IP); do  ssh Reports@$i showsys | awk '{print $2,$5}' | column -t ; ssh Reports@$i showpd -degraded -failed | awk '{print $1,$2,$3,$5}' ; done | grep -v "MiB" | grep -v "total" | grep -B 4 -iE "failed|degraded"

Modifications:

Pipe the output with grep -B 4 -iE "failed|degraded"

  • OP also wants to convert the result to a CSV format. – Haxiel Mar 20 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.