0

I have this output from a drive diag command.

Slot Number        : 0   
Drive's position   : DiskGroup 0  
Media Error        : 0   
Other Error        : 0   
Predictive Failure : 0   
Raw Size           : 447.130 GB [0x37e436b0 Sectors]
Firmware state     : Online, Spun Up 
Inquiry Data       : PHYM813201FL480BGNSSDSC2KG480G7R SCV1DL58  
Foreign State      : None   
Media Type         : Solid State Device 
Temperature        : 20C (68.00 F) 
S.M.A.R.T alert    : No   

Slot Number        : 1   
Drive's position   : DiskGroup 0  
Media Error        : 0   
Other Error        : 0   
Predictive Failure : 0   
Raw Size           : 447.130 GB [0x37e436b0 Sectors]
Firmware state     : Online, Spun Up 
Inquiry Data       : PHYM81320058480BGNSSDSC2KG480G7R SCV1DL58  
Foreign State      : None   
Media Type         : Solid State Device 
Temperature        : 21C (69.80 F) 
S.M.A.R.T alert    : No   

Slot Number        : 2   
Drive's position   : DiskGroup 1  
Media Error        : 0   
Other Error        : 0   
Predictive Failure : 0   
Raw Size           : 1.090 TB [0x8bba0cb0 Sectors]
Firmware state     : Online, Spun Up 
Inquiry Data       : SEAGATE ST1200MM0099 ST31WFK0VEBK 
Foreign State      : None   
Media Type         : Hard Disk Device 
Temperature        : 22C (71.60 F) 
S.M.A.R.T alert    : No   

Slot Number        : 3   
Drive's position   : DiskGroup 1  
Media Error        : 0   
Other Error        : 0   
Predictive Failure : 0   
Raw Size           : 1.090 TB [0x8bba0cb0 Sectors]
Firmware state     : Online, Spun Up 
Inquiry Data       : SEAGATE ST1200MM0099 ST31WFK0T07T 
Foreign State      : None   
Media Type         : Hard Disk Device 
Temperature        : 22C (71.60 F) 
S.M.A.R.T alert    : No   

Slot Number        : 4   
Drive's position   : DiskGroup 1  
Media Error        : 0   
Other Error        : 0   
Predictive Failure : 0   
Raw Size           : 1.090 TB [0x8bba0cb0 Sectors]
Firmware state     : Online, Spun Up 
Inquiry Data       : SEAGATE ST1200MM0099 ST31WFK0VAJK 
Foreign State      : None   
Media Type         : Hard Disk Device 
Temperature        : 22C (71.60 F) 
S.M.A.R.T alert    : No   

Slot Number        : 5   
Drive's position   : DiskGroup 1  
Media Error        : 0   
Other Error        : 0   
Predictive Failure : 0   
Raw Size           : 1.090 TB [0x8bba0cb0 Sectors]
Firmware state     : Online, Spun Up 
Inquiry Data       : SEAGATE ST1200MM0099 ST31WFK0SYPC 
Foreign State      : None   
Media Type         : Hard Disk Device 
Temperature        : 22C (71.60 F) 
S.M.A.R.T alert    : No   

Slot Number        : 6   
Drive's position   : DiskGroup 1  
Media Error        : 0   
Other Error        : 0   
Predictive Failure : 0   
Raw Size           : 1.090 TB [0x8bba0cb0 Sectors]
Firmware state     : Online, Spun Up 
Inquiry Data       : SEAGATE ST1200MM0099 ST31WFK0MVN2 
Foreign State      : None   
Media Type         : Hard Disk Device 
Temperature        : 22C (71.60 F) 
S.M.A.R.T alert    : No   

Slot Number        : 7   
Drive's position   : DiskGroup 1  
Media Error        : 0   
Other Error        : 0   
Predictive Failure : 0   
Raw Size           : 1.090 TB [0x8bba0cb0 Sectors]
Firmware state     : Online, Spun Up 
Inquiry Data       : SEAGATE ST1200MM0099 ST31WFK0SZ2L 
Foreign State      : None   
Media Type         : Hard Disk Device 
Temperature        : 22C (71.60 F) 
S.M.A.R.T alert    : No 

And I would like to only make changes on the 3,4,5,7,9 and 12th line after the ":" sign. Those results are the standards but I want to add some color if it says something different. For example:

Slot Number        : 7   
Drive's position   : DiskGroup 1  
Media Error        : 4  (I want the whole line in red)
Other Error        : 3  (I want the whole line in red)
Predictive Failure : 1  (I want the whole line in red)
Raw Size           : 1.090 TB [0x8bba0cb0 Sectors]
Firmware state     : Failed. (I want the whole line in red)
Inquiry Data       : SEAGATE ST1200MM0099 ST31WFK0SZ2L 
Foreign State      : Unconfigured  (I want the whole line in red)
Media Type         : Hard Disk Device 
Temperature        : 22C (71.60 F) 
S.M.A.R.T alert    : Yes  (I want the whole line in red)

I would like to make those changes for every drive, the drive quantity is variable, sometimes is more sometimes is less.

  • What did you try and why wasn't it working as you expect? – Renaud Pacalet Apr 08 '22 at 04:43
  • This is not a duplicate. `awk -F '[[:blank:]]+:[[:blank:]]+ '` may be helpful to split the output in to key (`$1`), and value (`$2`). Then you can use awk pattern/action blocks to match, eg: `awk -F '[[:blank:]]+:[[:blank:]]+' '$1~/^(Media Error|Other Error|Predictive Failure)$/ && $2 > 0 { print "\033[31m" $0 "\e[0m"; next} 1'` should get you half way there. – dan Apr 08 '22 at 05:07
  • @dan Thanks for the recommendation, i still thet the same output but color doesnt change – Josue Baquerizo Apr 09 '22 at 01:20
  • @JosueBaquerizo You may need to adjust the match patterns. Look for varying whitespace in particular, also check quoting is correct. I tested with your data and got three red lines. – dan Apr 09 '22 at 03:31

0 Answers0