Checkpoint - turn netconf.C routes into linux route command
I must confess that I prefer good solutions today over perfect solutions tomorrow. So when the need aroused to do a script that takes netconf.C and transforms all the route statements in it to the general linux form of "route add xxx" I did this one-liner you can see below. The script looks ugly and sketchy but it works.
awk ' (/dest/ || /via/) && ! /127.0.0.0/ ' /etc/sysconfig/netconf.C | sed 's/[():]/ /g' | sed ' s/^.* via/ gw/' | sed ' s/^.*dest / route add -net /' | awk ' {if($0~/\/32/) { gsub(/-net/,"-host "); print} else print} '| awk ' {if(NR % 2 == 1) {gsub(/$/," "); printf($0)} else print} '
After you run it on the gateway you will get something like that to the stdout:
route add -net "192.168.9.0/22" gw 10.20.20.6
route add -net "172.16.11.0/24" gw 10.20.20.6
route add -net "172.16.12.0/24" gw 10.20.20.6
route add -net "172.16.13.0/24" gw 10.20.20.6
Follow me on https://www.linkedin.com/in/yurislobodyanyuk/ not to miss what I publish on Linkedin, Github, blog, and more.