> I am using 2.2.19 Eigerstein beta. I have a bit of a question about expr. > > I have the following line in a script to work out what the network address > is. > > network=`expr $ptpaddr : '\([0-9]*\.[0-9]*\.[0-9]*\.\)'`0 > > This works ok under red hat linux, but lrp gives > > # bash test > exp: arith: syntax error: "192.168.9.234 : \([0-9]*\.[0-9]*\.[0-9]*\.\)" > > Does anyone have a workaround for this. I am trying to automate the process > of setting up the VPN links with CIPE rather than hard coding the ip address > directly.
There is no expr command provided with lrp. You can do basic math using $(( )) shell expansion (the expr command is aliased to $(( )) shell expansion, btw), and most any other expr tasks using sed. The following sed command extracts the first dot-quad notation address it finds on a line and returns it, deleting everything else: sed 's/^[^.0-9]*\([.0-9]*\).*$/\1/' Note that it does not explicitly check to verify there are FOUR sets of numbers, it just looks for the first group of numbers and/or . (dot). If you have lots of other numbers potentially confusing the pattern match, you should use the longer \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]\) pattern to match only a dot-quad formatted string. You can also convert CIDR (ie /24) netmasks to/from dot-quad netmasks (ie 255.255.255.0), and pretty much anything else you need to do using only shell-script and possibly sed. See the dot_to_length () procedure below, for a practical example (extracted from /etc/dhclient-script...part of my dhclient package). If you need something specific and can't get it running, post your requirements to the list and someone here can probably help you make it go. Charles Steinkuehler http://lrp.steinkuehler.net http://c0wz.steinkuehler.net (lrp.c0wz.com mirror) dot_to_length() { #subnet_length is our result subnet_length=0 local oct1 oct2 oct3 oct4 oct_tmp count # Strip the four octets from the dot notation netmask oct1=`echo $1 | sed -e 's/^\(.*\)\..*\..*\..*$/\1/'` oct2=`echo $1 | sed -e 's/^.*\.\(.*\)\..*\..*$/\1/'` oct3=`echo $1 | sed -e 's/^.*\..*\.\(.*\)\..*$/\1/'` oct4=`echo $1 | sed -e 's/^.*\..*\..*\.\(.*\)$/\1/'` # Skip over any octets that are 255, adding 8 to the # netmask length for each byte # Store the first fractional byte in $oct_tmp oct_tmp=$oct1 if [ $oct1 -eq 255 ]; then subnet_length=`expr $subnet_length + 8` otc_tmp=$oct2 if [ $oct2 -eq 255 ]; then subnet_length=`expr $subnet_length + 8` oct_tmp=$oct3 if [ $oct3 -eq 255 ]; then subnet_length=`expr $subnet_length + 8` oct_tmp=$oct4 if [ $oct4 -eq 255 ]; then oct_tmp=0 subnet_length=`expr $subnet_length + 8` fi fi fi fi # Now convert the fractional byte (if any) to a bit length. # Only legal netmask bit patterns are accepted. count=0 if [ $oct_tmp -gt 0 ]; then for bit in `echo 128 192 224 240 248 252 254 0`; do count=`expr $count + 1` if [ $oct_tmp -eq $bit ]; then oct_tmp=`expr $oct_tmp - $bit` subnet_length=`expr $subnet_length + $count` break fi if [ $count -eq 8 ]; then echo ERROR:Illegal subnet mask value! fi done fi } _______________________________________________ Leaf-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/leaf-user
