Skip to contentSkip to conversation

ver_linux: gcc -dumpversion, use regex to find version number

PATCH In review Alexander Kapshuk 3 participants 29 messages Oct 12, 2015 – Dec 2, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/22 ver_linux: gcc -dumpversion, use regex to find version number

Rely on regex to find the version number, rather than a field number.

---
 scripts/ver_linux | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/ver_linux +6 -2
index 7de36df..af6467e 100755
@@ -11,8 +11,12 @@ echo ' '
 uname -a
 echo ' '
 
-gcc -dumpversion 2>&1| awk \
-'NR==1{print "Gnu C                 ", $1}'
+gcc -dumpversion 2>&1 |
+awk '/[0-9]+([.]?[0-9]+)+/ && !/not found$/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("GNU C\t\t\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 make --version 2>&1 | awk -F, '{print $1}' | awk \
       '/GNU Make/{print "Gnu make              ",$NF}'
Signature · 1 line
2.4.9
#1 lore raw

PATCH 2/22 ver_linux: make --version, use regex to find version number

Rely on regex to find the version number, rather than a field number. Reduce the number of 'awk' invocations from two to one.

---
 scripts/ver_linux | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/ver_linux +6 -2
index af6467e..31c0e4d 100755
@@ -18,8 +18,12 @@ awk '/[0-9]+([.]?[0-9]+)+/ && !/not found$/{
 	substr($0,RSTART,RLENGTH))
 }'
 
-make --version 2>&1 | awk -F, '{print $1}' | awk \
-      '/GNU Make/{print "Gnu make              ",$NF}'
+make --version 2>&1 |
+awk '/GNU Make/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("GNU Make\t\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 echo "binutils               $(ld -v | egrep -o '[0-9]+\.[0-9\.]+')"
 
Signature · 1 line
2.4.9
#2 lore raw

PATCH 3/22 ver_linux: binutils, fix inaccurate output

In reply to Alexander Kapshuk

Current implementation output on Gentoo Linux:
binutils 2.25.1
1.1
2.25.1

Proposed implementation:
Binutils 2.25.1

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

Rely on regex to find the version number.

---
 scripts/ver_linux | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
scripts/ver_linux +6 -1
index 31c0e4d..1fea749 100755
@@ -25,7 +25,12 @@ awk '/GNU Make/{
 	substr($0,RSTART,RLENGTH))
 }'
 
-echo "binutils               $(ld -v | egrep -o '[0-9]+\.[0-9\.]+')"
+ld -v 2>&1 |
+awk '/[0-9]+([.]?[0-9]+)+/ && !/not found$/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("Binutils\t\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 echo -n "util-linux             "
 fdformat --version | awk '{print $NF}' | sed -e s/^util-linux-// -e s/\)$//
Signature · 1 line
2.4.9
#3 lore raw

PATCH 4/22 ver_linux: util-linux, 'fdformat' not ubiquitous any longer

In reply to Alexander Kapshuk

The current implementation relies on 'fdformat' to output the version of 'util-linux'. This does not seem to be reliable any longer, as 'fdformat' does not seem to come preinstalled in all ditros these days.

The proposed implementation uses 'mount' to output both the version of 'util-linux' and 'mount' proper, as 'mount' is also a part of the 'util-linux' package.

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

Rely on regex to find the version number, rather than a field number.

---
 scripts/ver_linux | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
scripts/ver_linux +6 -5
index 1fea749..28e7640 100755
@@ -32,11 +32,12 @@ awk '/[0-9]+([.]?[0-9]+)+/ && !/not found$/{
 	substr($0,RSTART,RLENGTH))
 }'
 
-echo -n "util-linux             "
-fdformat --version | awk '{print $NF}' | sed -e s/^util-linux-// -e s/\)$//
-
-echo -n "mount                  "
-mount --version | awk '{print $NF}' | sed -e s/^mount-// -e s/\)$//
+mount --version 2>&1 |
+awk '/[0-9]+([.]?[0-9]+)+/ && !/not found$/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	$0 = substr($0,RSTART,RLENGTH)
+	printf("Util-linux\t\t%s\nMount\t\t\t%s\n",$0,$0)
+}'
 
 depmod -V  2>&1 | awk 'NR==1 {print "module-init-tools     ",$NF}'
 
Signature · 1 line
2.4.9
#4 lore raw

Re: [PATCH 04/22] ver_linux: util-linux, 'fdformat' not ubiquitous any longer

Quoted 3 lines · Alexander Kapshuk

The current implementation relies on 'fdformat' to output the version of 'util-linux'. This does not seem to be reliable any longer, as 'fdformat' does not seem to come preinstalled in all ditros these days.

No fdformat?! Hmph, kids today with their shiny SSDs. But seriously, if you want to drop fdformat as the canonical util-linux program, should Documentation/Changes should be updated too?

Signature · 1 line
Jim
#5 lore raw

PATCH 5/22 ver_linux: module-init-tools, look for numerical input, not field number

In reply to Alexander Kapshuk

Rely on regex to find the version number, rather than rely on numerical input to be found in a particular input field.

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

---
 scripts/ver_linux | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
scripts/ver_linux +6 -1
index 28e7640..7cc74d1 100755
@@ -39,7 +39,12 @@ awk '/[0-9]+([.]?[0-9]+)+/ && !/not found$/{
 	printf("Util-linux\t\t%s\nMount\t\t\t%s\n",$0,$0)
 }'
 
-depmod -V  2>&1 | awk 'NR==1 {print "module-init-tools     ",$NF}'
+depmod -V  2>&1 |
+awk '/[0-9]+([.]?[0-9]+)+/ && !/not found$/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("Module-init-tools\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 tune2fs 2>&1 | grep "^tune2fs" | sed 's/,//' |  awk \
 'NR==1 {print "e2fsprogs             ", $2}'
Signature · 1 line
2.4.9
#6 lore raw

PATCH 6/22 ver_linux: e2fsprogs, look for numerical input, not field number

In reply to Alexander Kapshuk

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

---
 scripts/ver_linux | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/ver_linux +6 -2
index 7cc74d1..2e1929f 100755
@@ -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}'
Signature · 1 line
2.4.9
#7 lore raw

PATCH 7/22 ver_linux: jfsutils, look for numerical input, not field number

In reply to Alexander Kapshuk

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'.

---
 scripts/ver_linux | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/ver_linux +6 -2
index 2e1929f..7d85447 100755
@@ -53,8 +53,12 @@ awk '/^tune2fs/{
 	substr($0,RSTART,RLENGTH))
 }'
 
-fsck.jfs -V 2>&1 | grep version | sed 's/,//' |  awk \
-'NR==1 {print "jfsutils              ", $3}'
+fsck.jfs -V 2>&1 |
+awk '/version/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("Jfsutils\t\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 reiserfsck -V 2>&1 | grep ^reiserfsck | awk \
 'NR==1{print "reiserfsprogs         ", $2}'
Signature · 1 line
2.4.9
#8 lore raw

PATCH 8/22 ver_linux: reiserfsprogs, look for numerical input, not field number

In reply to Alexander Kapshuk

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' + 'awk'.

---
 scripts/ver_linux | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/ver_linux +6 -2
index 7d85447..65d4c02 100755
@@ -60,8 +60,12 @@ awk '/version/{
 	substr($0,RSTART,RLENGTH))
 }'
 
-reiserfsck -V 2>&1 | grep ^reiserfsck | awk \
-'NR==1{print "reiserfsprogs         ", $2}'
+reiserfsck -V 2>&1 |
+awk '/^reiserfsck/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("Reiserfsprogs\t\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 fsck.reiser4 -V 2>&1 | grep ^fsck.reiser4 | awk \
 'NR==1{print "reiser4progs          ", $2}'
Signature · 1 line
2.4.9
#9 lore raw

PATCH 9/22 ver_linux: xfsprogs, look for numerical input, not field number

In reply to Alexander Kapshuk

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' + 'awk'.

---
 scripts/ver_linux | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/ver_linux +6 -2
index 65d4c02..a926225 100755
@@ -70,8 +70,12 @@ awk '/^reiserfsck/{
 fsck.reiser4 -V 2>&1 | grep ^fsck.reiser4 | awk \
 'NR==1{print "reiser4progs          ", $2}'
 
-xfs_db -V 2>&1 | grep version | awk \
-'NR==1{print "xfsprogs              ", $3}'
+xfs_db -V 2>&1 |
+awk '/version/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("Xfsprogs\t\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 pccardctl -V 2>&1| grep pcmciautils | awk '{print "pcmciautils           ", $2}'
 
Signature · 1 line
2.4.9
#10 lore raw

PATCH 10/22 ver_linux: pcmciautils, look for numerical input, not field number

In reply to Alexander Kapshuk

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' + 'awk'.

---
 scripts/ver_linux | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
scripts/ver_linux +6 -1
index a926225..e36cceb 100755
@@ -77,7 +77,12 @@ awk '/version/{
 	substr($0,RSTART,RLENGTH))
 }'
 
-pccardctl -V 2>&1| grep pcmciautils | awk '{print "pcmciautils           ", $2}'
+pccardctl -V 2>&1 |
+awk '/pcmciautils/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("Pcmciautils\t\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 cardmgr -V 2>&1| grep version | awk \
 'NR==1{print "pcmcia-cs             ", $3}'
Signature · 1 line
2.4.9
#11 lore raw

PATCH 11/22 ver_linux: quota-tools, look for numerical input, not field number

In reply to Alexander Kapshuk

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' + 'awk'.

---
 scripts/ver_linux | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/ver_linux +6 -2
index e36cceb..d5b342e 100755
@@ -87,8 +87,12 @@ awk '/pcmciautils/{
 cardmgr -V 2>&1| grep version | awk \
 'NR==1{print "pcmcia-cs             ", $3}'
 
-quota -V 2>&1 | grep version | awk \
-'NR==1{print "quota-tools           ", $NF}'
+quota -V 2>&1 |
+awk '/version/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("Quota-tools\t\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 pppd --version 2>&1| grep version | awk \
 'NR==1{print "PPP                   ", $3}'
Signature · 1 line
2.4.9
#12 lore raw

PATCH 12/22 ver_linux: ppp, look for numerical input, not field number

In reply to Alexander Kapshuk

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' + 'awk'.

Tested on:
Oracle Linux

---
 scripts/ver_linux | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/ver_linux +6 -2
index d5b342e..af5ac82 100755
@@ -94,8 +94,12 @@ awk '/version/{
 	substr($0,RSTART,RLENGTH))
 }'
 
-pppd --version 2>&1| grep version | awk \
-'NR==1{print "PPP                   ", $3}'
+pppd --version 2>&1 |
+awk '/version/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("PPP\t\t\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 isdnctrl 2>&1 | grep version | awk \
 'NR==1{print "isdn4k-utils          ", $NF}'
Signature · 1 line
2.4.9
#13 lore raw

PATCH 13/22 ver_linux: libc, input redirection to sed fails in some distros

In reply to Alexander Kapshuk

The current implementation has been found not to work across all distros.

The proposed implementation relies on 'sed' to both output the string 'Linux C Library' as well as to open '/proc/self/maps' without having to use output redirection.

Tested on:
Gentoo Linux
Debian 6.0.10
Oracle Linux Server release 7.1
Arch Linux
openSuSE 13.2

---
 scripts/ver_linux | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/ver_linux +6 -2
index af5ac82..909d039 100755
@@ -107,8 +107,12 @@ isdnctrl 2>&1 | grep version | awk \
 showmount --version 2>&1 | grep nfs-utils | awk \
 'NR==1{print "nfs-utils             ", $NF}'
 
-echo -n "Linux C Library        "
-sed -n -e '/^.*\/libc-\([^/]*\)\.so$/{s//\1/;p;q}' < /proc/self/maps
+test -r /proc/self/maps &&
+sed '
+	/.*libc-\(.*\)\.so$/!d
+	s//Linux C Library\t\t\1/
+	q
+' /proc/self/maps
 
 ldd -v > /dev/null 2>&1 && ldd -v || ldd --version |head -n 1 | awk \
 'NR==1{print "Dynamic linker (ldd)  ", $NF}'
Signature · 1 line
2.4.9
#14 lore raw

PATCH 14/22 ver_linux: ldd, look for numerical input, not field number

In reply to Alexander Kapshuk

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 'head' + 'awk'.

The '-v' flag either seems to have been deprecated in some distros, e.g. Gentoo, or is an alias for '--version' in others. The proposed implementation uses the latter flag only.

---
 scripts/ver_linux | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/ver_linux +6 -2
index 909d039..a7d0eca 100755
@@ -114,8 +114,12 @@ sed '
 	q
 ' /proc/self/maps
 
-ldd -v > /dev/null 2>&1 && ldd -v || ldd --version |head -n 1 | awk \
-'NR==1{print "Dynamic linker (ldd)  ", $NF}'
+ldd --version 2>&1 |
+awk '/^ldd/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("Dynamic linker (ldd)\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 ls -l /usr/lib/libg++.so /usr/lib/libstdc++.so  2>/dev/null | awk -F. \
        '{print "Linux C++ Library      " $4"."$5"."$6}'
Signature · 1 line
2.4.9
#15 lore raw

PATCH 15/22 ver_linux: libcpp, fix missing output

In reply to Alexander Kapshuk

Neither 'libg++.so', nor 'libstdc++.so' were found where the current implementation expects them to be found in the distros below.

Gentoo Linux
Debian 6.0.10
Oracle Linux Server release 7.1

Which results in zero ouput generated.

The proposed implementation relies on 'ldconfig' to locate the libraries in question. 'Sed' is used to do the text processing.

---
 scripts/ver_linux | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
scripts/ver_linux +12 -3
index a7d0eca..882ddb9 100755
@@ -121,9 +121,18 @@ awk '/^ldd/{
 	substr($0,RSTART,RLENGTH))
 }'
 
-ls -l /usr/lib/libg++.so /usr/lib/libstdc++.so  2>/dev/null | awk -F. \
-       '{print "Linux C++ Library      " $4"."$5"."$6}'
-
+libcpp=`ldconfig -p 2>/dev/null |
+	awk '/(libg|stdc)[+]+\.so/ {
+	print $NF
+	exit
+	}
+'`
+test -r "$libcpp" &&
+ls -l $libcpp |
+sed '
+	s!.*so\.!!
+	s!^!Linux C++ Library\t!
+'
 ps --version 2>&1 | grep version | awk \
 'NR==1{print "Procps                ", $NF}'
 
Signature · 1 line
2.4.9
#16 lore raw

PATCH 16/22 ver_linux: procps, look for numerical input, not field number

In reply to Alexander Kapshuk

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' + 'awk'.

---
 scripts/ver_linux | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/ver_linux +6 -2
index 882ddb9..2269803 100755
@@ -133,8 +133,12 @@ sed '
 	s!.*so\.!!
 	s!^!Linux C++ Library\t!
 '
-ps --version 2>&1 | grep version | awk \
-'NR==1{print "Procps                ", $NF}'
+ps --version 2>&1 |
+awk '/version/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("Procps\t\t\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 ifconfig --version 2>&1 | grep tools | awk \
 'NR==1{print "Net-tools             ", $NF}'
Signature · 1 line
2.4.9
#17 lore raw

PATCH 17/22 ver_linux: net-tools, look for numerical input, not field number

In reply to Alexander Kapshuk

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' + 'awk'.

---
 scripts/ver_linux | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/ver_linux +6 -2
index 2269803..4ef1b7d 100755
@@ -140,8 +140,12 @@ awk '/version/{
 	substr($0,RSTART,RLENGTH))
 }'
 
-ifconfig --version 2>&1 | grep tools | awk \
-'NR==1{print "Net-tools             ", $NF}'
+ifconfig --version 2>&1 |
+awk '/tools/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("Net-tools\t\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 # Kbd needs 'loadkeys -h',
 loadkeys -h 2>&1 | awk \
Signature · 1 line
2.4.9
#18 lore raw

PATCH 18/22 ver_linux: loadkeys, look for numerical input, not field number

In reply to Alexander Kapshuk

'loadkeys -h' no longer prints the version number across all distros, despite the claim to do so in the manpage, which I found to be the case on a Debian Linux system.

The proposed implementation utilises the output of 'loadkeys -V' to acquire the version of both 'Kbd' and 'Console-tools'.

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

Rely on regex to find the version number, rather than rely on numerical input to be found in a particular input field.

---
 scripts/ver_linux | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
scripts/ver_linux +6 -7
index 4ef1b7d..e6b57d5 100755
@@ -147,13 +147,12 @@ awk '/tools/{
 	substr($0,RSTART,RLENGTH))
 }'
 
-# Kbd needs 'loadkeys -h',
-loadkeys -h 2>&1 | awk \
-'(NR==1 && ($3 !~ /option/)) {print "Kbd                   ", $3}'
-
-# while console-tools needs 'loadkeys -V'.
-loadkeys -V 2>&1 | awk \
-'(NR==1 && ($2 ~ /console-tools/)) {print "Console-tools         ", $3}'
+loadkeys -V 2>&1 |
+awk '/[0-9]+([.]?[0-9]+)+/ && !/not found$/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	$0 = substr($0,RSTART,RLENGTH)
+	printf("Kbd\t\t\t%s\nConsole-tools\t\t%s\n",$0,$0)
+}'
 
 oprofiled --version 2>&1 | awk \
 '(NR==1 && ($2 == "oprofile")) {print "oprofile              ", $3}'
Signature · 1 line
2.4.9
#19 lore raw

PATCH 19/22 ver_linux: sh-utils, look for numerical input, not field number

In reply to Alexander Kapshuk

Rely on regex to find the version number, rather than rely on numerical input to be found in a particular input field.

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

---
 scripts/ver_linux | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
scripts/ver_linux +6 -1
index e6b57d5..1c6ec22 100755
@@ -157,7 +157,12 @@ awk '/[0-9]+([.]?[0-9]+)+/ && !/not found$/{
 oprofiled --version 2>&1 | awk \
 '(NR==1 && ($2 == "oprofile")) {print "oprofile              ", $3}'
 
-expr --v 2>&1 | awk 'NR==1{print "Sh-utils              ", $NF}'
+expr --v 2>&1 |
+awk '/^expr/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("Sh-utils\t\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 udevinfo -V 2>&1 | grep version | awk '{print "udev                  ", $3}'
 
Signature · 1 line
2.4.9
#20 lore raw

PATCH 20/22 ver_linux: use 'udevadm', instead of 'udevinfo'

In reply to Alexander Kapshuk

'udevinfo' no longer seems to be available across various distros. 'udevadm' seems to be the currently valid way to look up the 'udev' version.

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

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' + 'awk'.

---
 scripts/ver_linux | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
scripts/ver_linux +6 -1
index 1c6ec22..f839be3 100755
@@ -164,7 +164,12 @@ awk '/^expr/{
 	substr($0,RSTART,RLENGTH))
 }'
 
-udevinfo -V 2>&1 | grep version | awk '{print "udev                  ", $3}'
+udevadm --version 2>&1 |
+awk '/[0-9]+([.]?[0-9]+)+/ && !/not found$/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("Udev\t\t\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 iwconfig --version 2>&1 | awk \
 '(NR==1 && ($3 == "version")) {print "wireless-tools        ",$4}'
Signature · 1 line
2.4.9
#21 lore raw

PATCH 21/22 ver_linux: wireless-tools, look for numerical input, not field number

In reply to Alexander Kapshuk

Rely on regex to find the version number, rather than rely on numerical input to be found in a particular input field.

Tested on:
Gentoo Linux

---
 scripts/ver_linux | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/ver_linux +6 -2
index f839be3..ae426c2 100755
@@ -171,8 +171,12 @@ awk '/[0-9]+([.]?[0-9]+)+/ && !/not found$/{
 	substr($0,RSTART,RLENGTH))
 }'
 
-iwconfig --version 2>&1 | awk \
-'(NR==1 && ($3 == "version")) {print "wireless-tools        ",$4}'
+iwconfig --version 2>&1 |
+awk '/version/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("Wireless-tools\t\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 if [ -e /proc/modules ]; then
     X=`cat /proc/modules | sed -e "s/ .*$//"`
Signature · 1 line
2.4.9
#22 lore raw

PATCH 22/22 ver_linux: proc/modules, limit text processing to 'sed'

In reply to Alexander Kapshuk

This patch is more of a personal preference, rather than a fix for a problem.

The current implementation used a combination of both 'cat' and 'sed' to generate an unsorted list of kernel modules separated by while space.

The proposed implementation uses 'sort' and 'sed' to generate a sort list of kernel modules separated by while space.

Tested on:
Gentoo Linux
Debian 6.0.10
Oracle Linux Server release 7.1
Arch Linux
openSuSE 13.2

---
 scripts/ver_linux | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
scripts/ver_linux +13 -4
index ae426c2..024a11a 100755
@@ -178,7 +178,16 @@ awk '/version/{
 	substr($0,RSTART,RLENGTH))
 }'
 
-if [ -e /proc/modules ]; then
-    X=`cat /proc/modules | sed -e "s/ .*$//"`
-    echo "Modules Loaded         "$X
-fi
+test -e /proc/modules &&
+sort /proc/modules |
+sed '
+	s/ .*//
+	H
+${
+	g
+	s/^\n/Modules Loaded\t\t/
+	y/\n/ /
+	q
+}
+	d
+'
Signature · 1 line
2.4.9
#23 lore raw

Re: [PATCH 22/22] ver_linux: proc/modules, limit text processing to 'sed'

Quoted 1 line · Alexander Kapshuk

This patch is more of a personal preference, rather than a fix for a problem.

Using the sed hold space isn't exactly easy to follow... if, unlike the other patches, there isn't some potential improvement over the status quo I'd suggest sticking with the original version.

Signature · 1 line
Jim
#24 lore raw

Re: [PATCH 22/22] ver_linux: proc/modules, limit text processing to 'sed'

Quoted 10 lines · Jim Davis
Quoted 1 line · Alexander Kapshuk

This patch is more of a personal preference, rather than a fix for a problem.

Using the sed hold space isn't exactly easy to follow... if, unlike the other patches, there isn't some potential improvement over the status quo I'd suggest sticking with the original version.

--
Jim

Thanks for your feedback.

If the use of a shell variable to store the generated list of modules be deemed more favourable than the use of the 'sed' hold space, may I at least suggest either of the two approaches below:

Sorted list:
Y=sort /proc/modules | sed 's/ .*$//'

Unsorted list:
Z=sed 's/ .*$//' /proc/modules

The use of 'cat' in the context of the original implementation is redundant.

#25 lore raw
In reply to Alexander Kapshuk

I tried out patches 1-22 on a Fedora 22 system with the v4.3-rc5 source tree; everything looks pretty good. The old ver_linux script didn't get the mount version right, but the new one does

< mount debug

Quoted 1 line

Mount 2.26.2

One minor thing with Net-tools, the old version printed

< Net-tools 2.10-alpha

while the regex the in the new version skips the '-alpha'

Quoted 1 line

Net-tools 2.10

Though I'm not a big fan of patch 22 (the sed hold space thing) there are several nice improvements all in all.

Signature · 1 line
Jim
#26 lore raw
Quoted 13 lines · Jim Davis

I tried out patches 1-22 on a Fedora 22 system with the v4.3-rc5 source tree; everything looks pretty good. The old ver_linux script didn't get the mount version right, but the new one does

< mount debug

Quoted 1 line

Mount 2.26.2

One minor thing with Net-tools, the old version printed

< Net-tools 2.10-alpha

while the regex the in the new version skips the '-alpha'

Quoted 7 lines
Quoted 1 line

Net-tools 2.10

Though I'm not a big fan of patch 22 (the sed hold space thing) there are several nice improvements all in all.

--
Jim

Thanks very much for reviewing the patches and for your commentary.

#27 lore raw
Quoted 16 lines · Alexander Kapshuk
Quoted 15 lines · Jim Davis

I tried out patches 1-22 on a Fedora 22 system with the v4.3-rc5 source tree; everything looks pretty good. The old ver_linux script didn't get the mount version right, but the new one does

< mount debug

Quoted 1 line

Mount 2.26.2

One minor thing with Net-tools, the old version printed

< Net-tools 2.10-alpha

while the regex the in the new version skips the '-alpha'

Quoted 1 line

Net-tools 2.10

Quoted 7 lines
Quoted 5 lines

Though I'm not a big fan of patch 22 (the sed hold space thing) there are several nice improvements all in all.

--
Jim

Thanks very much for reviewing the patches and for your commentary.

You're welcome, but I think you may need to run checkpatch -- from a quick test there were a few minor whitespace issues.

Signature · 1 line
Jim
#28 lore raw
In reply to Alexander Kapshuk
Quoted 1 line · Alexander Kapshuk

Rely on regex to find the version number, rather than a field

number.

Are you sure that is good idea?

I'd say that the field number is going to fail in more obvious way, which is a good thing.
Pavel

Quoted 24 lines
---
 scripts/ver_linux | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/ver_linux +6 -2
index 7de36df..af6467e 100755
@@ -11,8 +11,12 @@ echo ' '
 uname -a
 echo ' '
 
-gcc -dumpversion 2>&1| awk \
-'NR==1{print "Gnu C                 ", $1}'
+gcc -dumpversion 2>&1 |
+awk '/[0-9]+([.]?[0-9]+)+/ && !/not found$/{
+	match($0, /[0-9]+([.]?[0-9]+)+/)
+	printf("GNU C\t\t\t%s\n",
+	substr($0,RSTART,RLENGTH))
+}'
 
 make --version 2>&1 | awk -F, '{print $1}' | awk \
       '/GNU Make/{print "Gnu make              ",$NF}'
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html