For anyone not interested in Linux, skip this post, it’ll just bore you…
I whipped up a tiny little script today to automate something that’s been bugging me for ages. At home, I have an unreliable router, particularly unreliable for DNS purposes. So I manually override the default DHCP settings and specify the ISP’s DNS servers directly. Today I wrote this little script for NetworkManagerDispatcher to do this automatically for me.
#!/bin/bash
# Script to dispatch NetworkManager events
#
# Update /etc/resolv.conf on thouse network
if [ -z "$1" ]; then
echo "$0: called with no interface" 1>&2
exit 1
fi
# Run the right scripts
if [ "$2" = "up" ] && [ "$1" = "eth1" ]
then
iwconfig $1 | grep ESSID | while read interface junk ieee essid nick
do
if [ "${essid:7:5}" = "T-Two" ]
then
cp /etc/resolv.conf.thouse /etc/resolv.conf
exit 0
fi
done
fi
If that’s double dutch to you, don’t worry. It’s a very custom script which only really applies to my situation, but you never know, it might be useful to somebody, somewhere, one day…

0 Responses to “My First NetworkManagerDispatcher Script”
Leave a Reply