/usr boot time dependencies

Paul Jakma paul at dishone.st
Wed Aug 20 14:08:39 UTC 2003


On Wed, 20 Aug 2003, Pekka Savola wrote:

> > > 
> > > sysctl -a | awk '$0 ~ /^net\.ipv6\.conf\./ { split($1,a,/\./); 
> > > foo[a[4]] = a[4]; } END {asort(foo); for (i in foo) { if (foo[i] != 
> > > "all" && foo[i] != "default") print foo[i];}}'
> > > 
> > > at a minimum, grep regex | awk '....' can nearly always trivially be
> > > replaced with: awk '$0 ~ /regex/ ....' - grep | awk -> no! :)

> At least the first three-line systctl -a parsing is WAY too
> confusing to a random John Doe reading the code.  Just because we
> can do it doesn't mean we have to.  This is not an obfuscated
> string parsing contest :-), 

:)

but look on it as:

$0 ~ /^net\.ipv6\.conf\./ {
	split($1,a,/\./);
	foo[a[4]] = a[4];
}

END {
	asort(foo);
	for (i in foo) {
		if (foo[i] != "all" && foo[i] != "default")
			print foo[i];
	}
}

and perhaps it makes more sense. NB: the above also strips out the 
'all' and 'default' interfaces which i dont think the while read 
interfaces needs.

Indeed, this is all a lot of work just to get the list of interfaces 
on a system, no? why not just read /proc directly instead of using 
sysctl? (sysctl uses proc, so proc must be available anyway):

	interfaces=`ls /proc/sys/net/ipv6/conf/`

or if you want to avoid the dependency on /proc, use the ip tool:

	/sbin/ip -6 link | awk '$1 ~ /^[0-9]/ { gsub(":","",$2); print $2}'

> when we could just have:
> 
> sysctl -a | grep "^net\.ipv6\.conf\." | awk -F. '{ print $4 }' |
> sort -u | while read interface;

no, at least get rid of the grep:

sysctl -a | grep "^net\.ipv6\.conf\." | awk -F. \
 '$0 ~ /^net\.ipv6\.conf\./ { print $4 }' | sort -u | while read  interface

or use the ip -6 link method :)

> perhaps the first grep could be eliminated, but it's much more
> readable if we keep it in.

dont see how. :)

(NB: I do have a penchant for awk)

> could be usable otherwise too.

Thinking about it, i think 'ip link' and 'ip -6 link' should be 
canonical source of interface info, no?

regards,
-- 
Paul Jakma	paul at clubi.ie	paul at jakma.org	Key ID: 64A2FF6A
	warning: do not ever send email to spam at dishone.st
Fortune:
Life would be so much easier if we could just look at the source code.
	-- Dave Olson





More information about the fedora-devel-list mailing list