support attribute cleanup for nice single value column
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 17 Feb 2020 19:13:01 +0000 (20:13 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 17 Feb 2020 19:13:01 +0000 (20:13 +0100)
smart-query.sh

index 5cf6212..3c1a9c4 100755 (executable)
@@ -1,17 +1,21 @@
-#!/bin/sh
+#!/bin/sh -e
 
-rm /tmp/s.last
+test -e /tmp/s.last && rm /tmp/s.last
 
-for col in "Device Model" "User Capacity"
+for col in "Device Model" "User Capacity" $*
 do
        # sed and sort is required for join later
-       grep "$col" /dev/shm/smart.sda.* | sed 's/:/: /' | sed "s/$col: */ : /" | sort | tee /tmp/s.this
+       grep "$col" /dev/shm/smart.sda.* | sed 's/:/: /' | sed \
+               -e "s/$col: */ : /" \
+               -e "s/[0-9]* $col .* \([0-9][0-9]*\)$/\1/" \
+       | sort > /tmp/s.this
 
        if [ -e /tmp/s.last ] ; then
-               join -a 1 /tmp/s.last /tmp/s.this | tee /tmp/s.new
+               join -a 1 /tmp/s.last /tmp/s.this > /tmp/s.new
+               mv /tmp/s.new /tmp/s.last
        else
                mv /tmp/s.this /tmp/s.last
        fi
 done
 
-cat /tmp/s.new | column -t -s :
+cat /tmp/s.last | column -t -s :