I use NetworkManager to connect to my wireless network and wanted a way to map the drives automagically when I connect. However, as I connect to a number of wireless access points I didn’t want to send my credentials trying to find my home server out each time I connect at the coffee shop.
Enter the NetworkManager dispatcher. Scripts in /etc/NetworkManager/dispatcher.d/ are executed when the network manager connection is made. I created the following file as “99mountmydrives” and chmodded it with execute permissions.
See the script below:
echo “running 99mountmydrives as `whoami`;” >> /tmp/dispatcher-log
echo “int=$1 and status=$2” >> /tmp/dispatcher-log
while [ -z “$PID” ]; do
echo “waiting.” >> /tmp/dispatcher-log
echo “waiting for nm-applet” >> /tmp/dispatcher-log
echo “mounting drives” >> /tmp/dispatcher-log
if [ “$IF” = “wlan0” ] && [ “$STATUS” = “up” ]; then
#WIFI Subnet at home
test=`ping -c 3 $SERVERIP >/dev/null;arp -a $SERVERIP`
echo “$test” >> /tmp/dispatcher-log
if expr “$test” : “.*$SERVERMAC” 2> /dev/null ; then