On 4/15/22 12:08 PM, Tim Woodall wrote:
On Fri, 15 Apr 2022, Greg Wooledge wrote:
On Fri, Apr 15, 2022 at 11:21:46AM -0400, Chuck Zmudzinski wrote:
Another improvement to the script would be to have the script toggle
the
default route on or off, depending on the existence or not of the
default
route, for the case when there is no argument to the script.
That requires some way to *determine* the current state. Parsing the
routing table, perhaps? If you could tell us how to do that, it might
help.
Try this (untested as I'm remote and don't want to remove my default
route!)
[[ -z "$( ip -6 route show exact default )" ]] && echo no
Hopefully will print no if there is no default route.
Tim.
This works well to determine the state and also prints a useful message
if the expected argument is not present:
#!/bin/bash
if [ "$1" == on ]
then
ip -6 route | grep default > /dev/null || \
ip -6 route add default via 2602:304:cef3:a430:d250:99ff:fe0b:b810
dev eth0
elif [ "$1" == off ]
then
ip -6 route | grep default > /dev/null && ip -6 route delete default
else
echo "The script ipv6 requires either on or off as the argument."
fi
I tested all four cases:
1. There is no default route, and the argument is on
2. There is no default route, and the argument is off
3. There is a default route, and the argument is on
4. There is a default route, and the argument is off
Works as expected.
Regards,
Chuck