Desculpas pela minha resposta anterior, que era a maneira que eu teria feito anos atrás. Parece que as coisas mudaram.
Acontece que o Network Manager executa TODOS os scripts no diretório /etc/NetworkManager/dispatcher.d/
(aqueles de raiz, que são executáveis, que não são legíveis por outros usuários e não são setuid), quando uma conexão é alterada (para cima, down, preup, predown).
Variáveis de ambiente são definidas e passadas para este script pelo gerenciador de rede. Você estará interessado na variável de ambiente CONNECTION_UUID (contém uma string exclusiva).
Então, para resolver seu problema (execute um script quando uma rede sem fio específica estiver conectada):
1) descubra o uuid da conexão sem fio que você está interessado (olhando dentro do arquivo de conexão apropriado no diretório /etc/NetworkManager/system-connections/
).
2) escreva um script bash (ou perl, ou python, ou qualquer outro) que faça o que você deseja se a variável de ambiente CONNECTION_UUID corresponder ao uuid da rede sem fio em (1) acima.
3) coloque este script em /etc/NetworkManager/dispatcher.d/
e defina o proprietário e as permissões adequadamente.
leitura adicional: man networkmanager (e um pequeno cutucando os scripts nos diretórios mencionados acima).
Um script de exemplo:
#!/bin/bash
#####################################
# MounterBeast Script
# /etc/NetworkManager/dispatcher.d/02remotemount
# Copyright 2011 Nathan E. Williams
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Usage:
# This script must be customized for your configuration.
# By default, the script will attempt to mount a CIFS share
# when a specified MAC address is found at the network gateway,
# or over sshfs if the MAC address of the gateway is not the specified MAC.
# e.g. I mount over CIFS to the servers internal IP when at home, and
# over sshfs when away from home.
#
# id gateway mac without physically checking the sticker:
# $ arp -n -a $(ip route show 0.0.0.0/0 | awk '{print }') | awk '{print }'
#
# Testing:
# up) sudo /etc/NetworkManager/dispatcher.d/02remotemount wlan0 up
# down) sudo /etc/NetworkManager/dispatcher.d/02remotemount wlan0 down
#####################################
#
# Configuration:
#
targetmac='xx:xx:xx:xx:xx:xx'
mount_user='$USER'
mount_pass='pass'
internal_server_name='192.168.1.102'
external_server_name='my.dyndns.com'
share_name="music"
mount_point='/mnt/remote'
ssh_port='22'
#
# Should not need to edit below
#
gateway=$(ip route show 0.0.0.0/0 | awk '{print }')
mactest=$(arp -n -a $gateway | awk '{print }')
if [[ "$mactest" == "$targetmac" ]]
then
case "" in
up)
sleep 5
mount -t cifs -o username=$mount_user,password=$mount_pass //$internal_server_name/$share_name $mount_point
;;
down)
umount -l $mount_point
;;
esac
else
case "" in
up)
sleep 5
sshfs -p $ssh_port $external_server_name:$share_name $mount_point
;;
down)
umount -l $mount_point
;;
esac
fi
exit $?