OSDN Git Service

ver_linux: e2fsprogs, look for numerical input, not field number
authorAlexander Kapshuk <alexander.kapshuk@gmail.com>
Mon, 12 Oct 2015 18:39:46 +0000 (21:39 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 18 Oct 2015 04:55:26 +0000 (21:55 -0700)
Rely on regex to find the version number, rather than rely on numerical input to be found in a particular input field.
Proposed implementation also eliminates the necessity to invoke 'grep' + 'sed' + 'awk'.

Tested on:
Gentoo Linux
Debian 6.0.10
Oracle Linux Server release 7.1

Signed-off-by: Alexander Kapshuk <alexander.kapshuk@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
scripts/ver_linux

index 7cc74d1..2e1929f 100755 (executable)
@@ -46,8 +46,12 @@ awk '/[0-9]+([.]?[0-9]+)+/ && !/not found$/{
        substr($0,RSTART,RLENGTH))
 }'
 
-tune2fs 2>&1 | grep "^tune2fs" | sed 's/,//' |  awk \
-'NR==1 {print "e2fsprogs             ", $2}'
+tune2fs 2>&1 |
+awk '/^tune2fs/{
+       match($0, /[0-9]+([.]?[0-9]+)+/)
+       printf("E2fsprogs\t\t%s\n",
+       substr($0,RSTART,RLENGTH))
+}'
 
 fsck.jfs -V 2>&1 | grep version | sed 's/,//' |  awk \
 'NR==1 {print "jfsutils              ", $3}'