So at work i use a vpn connection and after that i have to manually set my route table so everything works, I'm trying to write a bash script which will easily distinguish between my home connection and my work connection and set the correct gateway:
#!/bin/bash
# Does the ppp0 interface exist?
cat /proc/net/dev | grep ppp0 > /dev/null
ppp_check=$?
if [ $ppp_check -ne 0 ]; then
# I'm at home and you should set the ppp0 gateway
ip r c default via $(ifconfig ppp0 | awk -F "P-t-P:" '{print $2}' | awk -F " " '{print $1}' | tr "\n" " " | awk '{$1=$1};1')
else
# I'm at work so you should set my work gateway
ip r c default via 1.1.1.1
fi
ip r a 2.2.2.2/24 dev tun0
.
.
.
ip r a 10.10.10.10/24 dev tun0
The problem is that the script always executes the code for setting the home gateway even though I'm at work and the first IF statement should be skipped.
Any ideas?