Hi,
Looking for some help understand a script that was written by someone else. I have edited it, added some stuff but have now run into a brick wall with what the script is doing (more how than what)
The script is looking through the output of
The section of the script somehow extracts some of this info using awk and then prints it in a format
Script
This sort of works but produces the following output:
|nvme0 |PHM274360038280AGN |38 |100% |0% |[385 |[26.3 |
The first five fields are correct, the last two are not
Which is sort of correct - BUT:
Looking for some help understand a script that was written by someone else. I have edited it, added some stuff but have now run into a brick wall with what the script is doing (more how than what)
The script is looking through the output of
smartctl -a /dev/nvme0
which produces the following input to the script
Code:
smartctl 7.2 2020-12-30 r5155 [FreeBSD 12.2-RELEASE-p9 amd64] (local build)
Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF INFORMATION SECTION ===
Model Number: INTEL SSDPE21D280GA
Serial Number: **************************
Firmware Version: E2010325
PCI Vendor/Subsystem ID: 0x8086
IEEE OUI Identifier: 0x5cd2e4
Controller ID: 0
NVMe Version: <1.2
Number of Namespaces: 1
Namespace 1 Size/Capacity: 280,065,171,456 [280 GB]
Namespace 1 Formatted LBA Size: 512
Local Time is: Wed Aug 18 15:33:37 2021 BST
Firmware Updates (0x02): 1 Slot
Optional Admin Commands (0x0007): Security Format Frmw_DL
Optional NVM Commands (0x0006): Wr_Unc DS_Mngmt
Log Page Attributes (0x02): Cmd_Eff_Lg
Maximum Data Transfer Size: 32 Pages
Supported Power States
St Op Max Active Idle RL RT WL WT Ent_Lat Ex_Lat
0 + 18.00W - - 0 0 0 0 0 0
Supported LBA Sizes (NSID 0x1)
Id Fmt Data Metadt Rel_Perf
0 + 512 0 2
=== START OF SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
SMART/Health Information (NVMe Log 0x02)
Critical Warning: 0x00
Temperature: 39 Celsius
Available Spare: 100%
Available Spare Threshold: 0%
Percentage Used: 0%
Data Units Read: 752,735 [385 GB] ***** These are what I am trying to pick up
Data Units Written: 51,418,383 [26.3 TB] ***** but I guess the space is interfering.
Host Read Commands: 26,493,506
Host Write Commands: 425,473,938
Controller Busy Time: 227
Power Cycles: 75
Power On Hours: 10,643
Unsafe Shutdowns: 41
Media and Data Integrity Errors: 0
Error Information Log Entries: 1
Error Information (NVMe Log 0x01, 16 of 64 entries)
Num ErrCount SQId CmdId Status PELoc LBA NSID VS
0 1 10 - 0xc00c - 0 - -
The section of the script somehow extracts some of this info using awk and then prints it in a format
Script
Code:
for drive in $NVME_list; do
(
devid=$(basename "$drive")
"$smartctl" -a "$drive" | \
awk -v device=$devid \ '
/Serial Number:/{serial=$3}
/Temperature:/{temp=$2} \
/Available Spare:/{avail_spare=$3} \
/Percentage Used:/{perc_used=$3} \
/Data Units Read:/{data_read=$5} \
/Data Units Read:/{data_read_unit=$6} \
/Data Units Written:/{data_written=$5} \
/Data Units Written:/{data_written_unit=$6} \
END {
printf "|%-6s|%-24s|%-4s|%-9s%|%-4s|%-11s|%-12s|\n",device,serial,temp,avail_spare,perc_used,data_read,data_written;
}'
) >> "$logfile"
done
(
echo "+------+------------------------+----+---------+----+-----------+------------+"
) >> "$logfile"
fi
|nvme0 |PHM274360038280AGN |38 |100% |0% |[385 |[26.3 |
The first five fields are correct, the last two are not
Which is sort of correct - BUT:
- I seem unable to get rid of the leftmost square brackets in the fields with 385 and 26.3
- I am also trying to pick up the GB & TB from the Data Units Read & Data Units Written lines and add these to the 385 and 26.3 in the output
- I seem unable to manipulate the various data_read and data_written. The _unit variables do hold the correct data (allbeit with a square bracket to the right - but I assume a similar solution to issue 1 would likely apply here
- I really don't understand how the awk command is doing what its doing