Bash help....ref BiduleOhm script extensions

Status
Not open for further replies.

wtfR6a

Explorer
Joined
Jan 9, 2016
Messages
88
I could do with some bash / awk consultation - trying to adjust this script to extract some data from my NVMe drives and want to tidy up the display a bit.

Code:
Data Units Read:                    322,661,649 [165 TB]


I want to extract the '165' from the 165 TB line which I did like this...

Code:
/Data Units Written:/{DataWrote=(substr($5,2));} \


which I think is fine and should continue to work as the value increases, right?

This one has me beat though...

Code:
Power On Hours:                    1,244


How can I remove the ',' (or multiple commas as the value grows). I there a way to strip all non-numeric characters from the value ???

thx in adv
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Yeah it should, but I'm not sure about the substr, why did you add it?

You can use tr to delete the commas: echo "test,test2,test3" | tr -d , ;)
 

wtfR6a

Explorer
Joined
Jan 9, 2016
Messages
88
Yeah it should, but I'm not sure about the substr, why did you add it?

You can use tr to delete the commas: echo "test,test2,test3" | tr -d , ;)

Thank you - Ill give that a try now. I added the subset to remove the "[" from the front. I'm out my depth here so happy to be corrected.

EDIT: Oh I see, us the tr -d [ to strip the bracket.....ahhhhhaaaaa
 

wtfR6a

Explorer
Joined
Jan 9, 2016
Messages
88
ok, I give up.... how do I add the "tr -d" bit into the awk expression assignment?

Code:
/Power On Hours:/{onHours=$4} \


????

thank you again.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Yeah, tr is more elegant than a substr for that, and more robust too ;)

Can you post the whole script please? (on pastebin if possible, it would be great because of the syntax highlighting it offers)
 

wtfR6a

Explorer
Joined
Jan 9, 2016
Messages
88
based on your original script and hacked for displaying my nvme drives....

http://pastebin.com/z4QLve66

just want to filter out that "," on the power on field and extract the TB read/written without the byte or '[]' brackets.

thanks in adv for your help,
 

wtfR6a

Explorer
Joined
Jan 9, 2016
Messages
88
heres the smartctl output - you need 6.5 to get at nvme smart data

Code:
[admin@FREENAS] /% sudo smartctl -a -d nvme /dev/nvme0
Password:
smartctl 6.5 2016-05-07 r4318 [FreeBSD 10.3-RELEASE-p3 amd64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Number:                       INTEL SSDPEDMD400G4D HHHL NVMe 400GB
Serial Number:                      CVxxxxxxxxxxxxxxxx
Firmware Version:                   8DV10102
PCI Vendor/Subsystem ID:            0x8086
IEEE OUI Identifier:                0x5cd2e4
Controller ID:                      0
Number of Namespaces:               1
Namespace 1 Size/Capacity:          400,088,457,216 [400 GB]
Namespace 1 Formatted LBA Size:     512
Local Time is:                      Mon May 30 17:26:30 2016 EDT
Firmware Updates (0x02):            1 Slot
Optional Admin Commands (0x0006):   Format Frmw_DL
Optional NVM Commands (0x0006):     Wr_Unc DS_Mngmt
Maximum Data Transfer Size:         32 Pages

Supported Power States
St Op     Max   Active     Idle   RL RT WL WT  Ent_Lat  Ex_Lat
0 +    25.00W       -        -    0  0  0  0        0       0

Supported LBA Sizes (NSID 0x1)
Id Fmt  Data  Metadt  Rel_Perf
0 +     512       0         2
1 -     512       8         2
2 -     512      16         2
3 -    4096       0         0
4 -    4096       8         0
5 -    4096      64         0
6 -    4096     128         0

=== START OF SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

SMART/Health Information (NVMe Log 0x02, NSID 0xffffffff)
Critical Warning:                   0x00
Temperature:                        38 Celsius
Available Spare:                    100%
Available Spare Threshold:          10%
Percentage Used:                    0%
Data Units Read:                    322,661,649 [165 TB]
Data Units Written:                 699,095,637 [357 TB]
Host Read Commands:                 34,421,431
Host Write Commands:                34,811,556
Controller Busy Time:               0
Power Cycles:                       118
Power On Hours:                     1,247
Unsafe Shutdowns:                   141
Media and Data Integrity Errors:    0
Error Information Log Entries:      0

Error Information (NVMe Log 0x01, max 64 entries)
No Errors Logged
 

wtfR6a

Explorer
Joined
Jan 9, 2016
Messages
88
phew..... problem solved. Is this a decent solution? I want to replace ALL commas in the numeric field hence the gsub.I couldn't make 'tr' work so RTFM'd and this is what I came up with.

Code:
        /Power On Hours:/{gsub(",","",$4); onHours=$4 } \
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Yep, gsub is the way to go AFAIK ;)

+1 for RTFM :)
 
Status
Not open for further replies.
Top