Added some stuff so that on reboot/power-outage, all 30 instances enabled don't try to start. So at any given time only one instance is enabled/started.
nano /root/ovpnstart.sh
#!/bin/sh
#del all currently enabled instances
ls /etc/openvpn/*.ovpn \
| while read -r OVPN_CONF
do OVPN_ID="$(basename ${OVPN_CONF%.*} | sed -e "s/\W/_/g")"
if [ openvpn.${OVPN_ID}.enabled == '1' ]; then
uci del openvpn.${OVPN_ID}.enabled
fi
done
#generate random
inst=$(grep -m1 -ao '[0-2][0-9]' /dev/urandom | head -n1 | sed 's/^0//;s/00/30/')
#enable random instance
uci set openvpn.${inst}.enabled="1"
#commit changes
uci commit openvpn
#start random instance
/etc/init.d/openvpn start $inst
chmod 755 /root/ovpnstart.sh
A better way, thanks to @pavelgl explaining it to me, is to not write unnecessarily to flash.
Only posting for people who might stumble upon this thread.
Leave the script simple
nano/vi /root/ovpnstart.sh
#!/bin/sh
inst=$(grep -m1 -ao '[0-2][0-9]' /dev/urandom | head -n1 | sed 's/^0//;s/00/30/')
/etc/init.d/openvpn start $inst
Leave all openvpn instances enabled, but disable the openvpn service(luci --> System --> Startup --> Initscripts(tab) --> Disable openvpn) by default to prevent its starting after reboot. Then insert the following into (luci --> System --> Startup --> Local Startup(tab)) before exit 0
sleep 30 && /root/ovpnstart.sh
Thus, after router reboot only one (random) openvpn instance will start.