#!/usr/bin/env bash interface="" do_routing_table=0 do_ODM=0 just_echo=0 function usage { retval="$1" ( echo "Usage: $0 -i interface [-r|-o] [-h] [-e]" echo "-i interface specifies what interface the routes are for" echo "-r says to add entries to the routing table (this script should just generate an error on dups, no big deal)" echo "-o says to add entries to the ODM (be careful about duplicates - this script will not avoiding adding dups)" echo "-h says to show this help message" echo "-e says to just echo what would be done - don't actually do it" ) 1>&2 } while [ "$#" -ge 1 ] do if [ "$1" = "-i" ] && [ "$#" -ge 2 ] then interface="$2" shift elif [ "$1" = "-r" ] then do_routing_table=1 elif [ "$1" = "-o" ] then do_ODM=1 elif [ "$1" = "-e" ] then just_echo=1 elif [ "$1" = "-h" ] then usage 0 else usage 1 fi shift done if [ $[$do_routing_table+$do_ODM] = 0 ] then echo Sorry, you must specify one or both of -r and -o 1>&2 usage 1 fi if [ "$interface" = "" ] then echo "Sorry, you must specify an interface with -i" 1>&2 usage 1 fi # add -net 137.110.243.0 netmask 255.255.255.0 gw # add -net 137.110.244.0 netmask 255.255.255.0 gw .. # add -net 137.110.245.0 netmask 255.255.255.0 gw .. # add -net 137.110.246.0 netmask 255.255.255.128 gw .. # add -net 137.110.246.128 netmask 255.255.255.128 gw # add -net 137.110.247.0 netmask 255.255.255.0 # esmf04m-root> lsattr -EHl inet0 # attribute value description user_settable # # hostname esmf04m Host Name True # gateway Gateway True # route net,-hopcount,0,,0,128.200.197.129 Route True # route net,-interface,-netmask,255.255.255.128,-if,en1,,128.200.197.128,128.200.197.129 # route net,-hopcount,0,-netmask,255.255.255.128,-if,en1,,0,128.200.197.129 # route net,-hopcount,0,,0,137.110.247.209 # route net,-hopcount,0,-netmask,255.255.255.240,-if,en3,,137.110.247.208,137.110.247.209 # route net,-hopcount,0,-netmask,255.255.255.0,-if,en3,,136.110.243.0,137.110.247.209 # route net,-hopcount,0,-netmask,255.255.255.0,-if,en3,,137.110.244.0,137.110.247.209 # route net,-hopcount,0,-netmask,255.255.255.0,-if,en3,,137.110.245.0,137.110.247.209 # route net,-hopcount,0,-netmask,255.255.255.128,-if,en3,,137.110.246.0,137.110.247.209 # route net,-hopcount,0,-netmask,255.255.255.128,-if,en3,,137.110.246.128,137.110.247.209 # route net,-hopcount,0,-netmask,255.255.255.0,-if,en3,,137.110.247.208,137.110.247.209 # route net,-hopcount,0,-netmask,255.255.255.0,-if,en3,,137.110.243.0,127.110.247.209 # route net,-hopcount,0,-netmask,255.255.255.0,-if,en3,,137.110.243.0,137.110.247.209 # bootup_option no Serial Optical Network Interface True # rout6 FDDI Network Interface True # authm 65536 Authentication Methods True # Wed Nov 16 14:20:30 #chdev -l inet0 -a "net,-hopcount,1,-netmask,255.255.255.0,207.156.168.0,10.0.15.254" #route [ -f ] [ -n ] [ -q ] [ -v ] Command [ Family ] [ [ -net | -host ] #Destination [ -prefixlen n] [ -netmask [ Address ] ] Gateway ] [ Arguments ] while read addword netoption network netmaskword netmask gwword gw dummy do case "$addword/$netoption/$netmaskword/$gwword/$dummy" in "add/-net/netmask/gw/") # echo Good line 1>&2 ODM="chdev -l inet0 -a net,-hopcount,0,-netmask,$netmask,-if,$interface,,$network,$gw" ROUTE="route add -net $network -netmask $netmask $gw" if [ "$do_routing_table" = 1 ] then if [ "$just_echo" = 1 ] then echo "$ROUTE" else eval "$ROUTE" fi fi if [ "$do_ODM" = 1 ] then if [ "$just_echo" = 1 ] then echo "$ODM" else eval "$ODM" fi fi ;; *) echo Bad line 1>&2 ;; esac done