I am attempting to port freeswan scripts that use ifconfig and awk to use
iproute and sed instead. I am posting these modifications to get input on
better ways of doing things, since I do believe that there are probably at
least 40-50 better ways to do it than I have come up with.
So far:
# get the physical device that leads to the default gateway
netstat -nr | awk '$1 == "0.0.0.0" && $3 == "0.0.0.0" { print $NF }'
# becomes this without netstat or awk
ip route | sed -e '/^default/!d' -e 's/^.* ([^ ]*) $/\1/'
and:
# set up some vars pertaining to $phys
eval `ifconfig $phys | awk '$1 == "inet" && $2 ~ /^addr:/ && $4 ~ /^Mask:/ {
gsub(/:/, " ", $0)
print "addr=" $3
if ($4 == "Bcast")
print "type=broadcast"
else if ($4 == "P-t-P")
print "type=pointopoint"
else
print "type="
print "otheraddr=" $5
print "mask=" $7
}'`
# becomes (something like) this without ifconfig or awk
eval `ip addr show dev $phys | sed -e '/^ *inet/!d' -e 's/^ *inet \(.*\)\/\(.*\)
\(.*\) \(.*\) \(.*\) \(.*\) \(.*\)/addr=\1;mask=\2;type=\3;otheraddr=\4;/'`
# of course, the type and mask are not the right format
Please let me know if this way of doing things is completely braindead or not.
Coming from a perl background, I am not afraid of a regex or two, even
complicated ones. I just am so unfamiliar with sed, I don't even have any
frame of reference.
Thanks in advance for your assistance.
---------------------------------------------------------------------------
Chad Carr [EMAIL PROTECTED]
---------------------------------------------------------------------------
_______________________________________________
Leaf-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-user