Script to check ip route
by cadillacrick from LinuxQuestions.org on (#55JSY)
Hey guys, first time post...
I'm trying to get a script to check if a route exists after I connect a VPN... First time trying to get this done and need some help...
This is what I have so far --
Code:#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
EXIST='ip route show 10.10.200.0/24 | wc -l'
if [$EXIST -eq 0]
then
echo "--- Route is down ---"
ip route add 10.10.200.0/24 via ppp1
fi
if [$EXIST -eq 1]
then
echo "---Route Enabled---"
fi
exit
Getting these errors when I try and run it...
./routecheck.sh: line 5: [ip: command not found
./routecheck.sh: line 11: [ip: command not found
If I run my command 'ip route show 10.10.200.0/24 | wc -l' it works fine.. i get a value of 1 when the route is active... but for some reason in the script it doesn't work... i'm sure i'm missing something stupid here.. but i'm new to this... so I need help please.
Thanks!
Richard


I'm trying to get a script to check if a route exists after I connect a VPN... First time trying to get this done and need some help...
This is what I have so far --
Code:#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
EXIST='ip route show 10.10.200.0/24 | wc -l'
if [$EXIST -eq 0]
then
echo "--- Route is down ---"
ip route add 10.10.200.0/24 via ppp1
fi
if [$EXIST -eq 1]
then
echo "---Route Enabled---"
fi
exit
Getting these errors when I try and run it...
./routecheck.sh: line 5: [ip: command not found
./routecheck.sh: line 11: [ip: command not found
If I run my command 'ip route show 10.10.200.0/24 | wc -l' it works fine.. i get a value of 1 when the route is active... but for some reason in the script it doesn't work... i'm sure i'm missing something stupid here.. but i'm new to this... so I need help please.
Thanks!
Richard