0

I have bash script to collect all hardware info but following memory info piece is missing, so this is what i am trying to do.

Following command give you status of DIMM memory module,

[root@Linux ~]# hpasmcli -s 'show dimm'

DIMM Configuration
------------------
Processor #:                     1
Module #:                     1
Present:                      Yes
Form Factor:                  9h
Memory Type:                  DDR3(18h)
Size:                         8192 MB
Speed:                        1333 MHz
Supports Lock Step:           No
Configured for Lock Step:     No
Status:                       Ok

Processor #:                     1
Module #:                     12
Present:                      Yes
Form Factor:                  9h
Memory Type:                  DDR3(18h)
Size:                         8192 MB
Speed:                        1333 MHz
Supports Lock Step:           No
Configured for Lock Step:     No
Status:                       Ok

Processor #:                     2
Module #:                     1
Present:                      Yes
Form Factor:                  9h
Memory Type:                  DDR3(18h)
Size:                         8192 MB
Speed:                        1333 MHz
Supports Lock Step:           No
Configured for Lock Step:     No
Status:                       Ok

Processor #:                     2
Module #:                     12
Present:                      Yes
Form Factor:                  9h
Memory Type:                  DDR3(18h)
Size:                         8192 MB
Speed:                        1333 MHz
Supports Lock Step:           No
Configured for Lock Step:     No
Status:                       DIMM is degraded

want to extract Size: and Status: and need that in single line, like following

Final output will look like following. I can use other language like python or perl but i wrote in bash so i need something in bash, i can do multiple for loop and play with variable to make it work but i need something easy or in-short single like like sed/awk. how can i achieve that in sed/awk?

8192MB - Ok
8192MB - OK
8192MB - OK 
8192MB - DIMM is degraded
1

A solution that doesn't grep | awk | sed | awk, but rather just uses one awk:

hpasmcli -s 'show dimm' | awk 'BEGIN { stick=0 } $1 == "Size:" { dimm[++stick] = $2" "$3} $1 == "Status:" { $1=""; status[stick]=$0 }  END {for( i in dimm ) { print dimm[i], "-", status[i] } }'
8192 MB - Ok
8192 MB - Ok
8192 MB - Ok
8192 MB - DIMM is degraded

The awk script, reformatted for readability:

BEGIN { 
  stick=0 
} 
$1 == "Size:" { 
  dimm[++stick] = $2" "$3
} 
$1 == "Status:" { 
  $1="" 
  status[stick]=$0
}  
END {
  for( i in dimm ) { 
    print dimm[i], "-", status[i] 
  } 
}'
0

Oh boy i think i did it :)

[root@Linux ~]# hpasmcli -s 'show dimm' | egrep -e Size -e Status | awk -F: '{print $2}' | sed 's/^[ \t]*//' | awk 'NR%2{printf "%s - ",$0;next;}1'
8192 MB - Ok
8192 MB - Ok
8192 MB - Ok
8192 MB - DIMM is degraded

Still i would like to know if anyother way we can do that, i am not going to answer my question i will wait for other folks to chime in.

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.