#!/bin/bash ROUTES='192.168.0.0,10.1.0.3 192.168.1.0,10.1.0.2' for route in $ROUTES do from=$(echo "$route" | awk -F',' '{print $1}') to=$(echo "$route" | awk -F',' '{print $2}') (ifconfig | grep $to > /dev/null) && [[ -z $(route | grep $from) ]] && route add -net $from/24 gw $to && echo "[$(date)] Adding route for $from/24 as $to is online but no route was configured." >> /var/log/nat-route.log done exit 0