The following is a snippet from a daily report script that checks on the SMART status of disks.
I’d like the full value of $STATUS to be printed in the ‘else’ clause, however, but it’s truncating it now to only the first word ($3).
How can I overcome this?
echo "SMART STATUS" >> $LOGS
echo "--------------------------" >> $LOGS
DISKS=( 0 1 2 3 4 5 6 7 )
for i in "${DISKS[@]}" ;
do
STATUS=`diskutil info /dev/disk$i | grep SMART | awk '{ print $3 }'`
if [ "$STATUS" = "Verified" ]; then
echo "SMART STATUS OK FOR DISK $i" >> $LOGS
else
echo "** SMART STATUS $STATUS FOR DISK $i **" >> $LOGS
fi
done
echo " " >> $LOGS
echo " " >> $LOGS
For example:
$ diskutil info /dev/disk8 | grep SMART
SMART Status: Not Supported
$ diskutil info /dev/disk2 | grep SMART
SMART Status: Verified
Ideally the script would echo “Not Supported” for cases like disk8. I think the value for “SMART Status:” may vary between one word and several. I don’t see all the possibilities on the man page, so I don’t have a definitive answer for this.
You can save the
grep, and put all things in awk:try this: