Running Scripts Using NetworkManager
For years now, I’ve had to run vpnc after connecting my school’s wireless. Truly, it never bothered me; however, at my new job, I need to run route after I connect to their wireless. For whatever reason, that got to me. I didn’t really want to run route when I wasn’t on their network (it likely wouldn’t have screwed anything up, but still…). So, I went about putting a quick bit in /etc/sysconfig/network-scripts/ifup-wireless, and it didn’t work… =\ So, after some digging, I’ve found another way using NetworkManager. Here’s what I did:
Because I hate hacking up scripts that services use, I wrote a quick script and put it in /usr/local/bin/wireless.sh:
#!/bin/bash if iwconfig|grep -c MY-WORK-ESSID then route add -net 18.104.22.168/22 gw 22.214.171.124 fi if iwconfig|grep -c msum-wireless then vpnc fi
Once that was done, I ran:
chmod +x /usr/local/bin/wireless.sh
and added the line:
to the file /etc/NetworkManager/dispatcher.d/00-netreport right before the exit.
And that’s it! It would be neat if NetworkManager added in similar functionality through the GUI, but until that day, this should work fine. Also, to note, those scripts are run as root, so be careful!
Upon upgrading from Fedora 14 to 15, the file 00-netreport was overwritten. I’ve done updates to NetworkManager, so that had nothing to do with it. In any case, if you end up upgrading your distro, there’s a chance that’ll get overwritten. In the event it does, you’ll just have to paste the line to the script again. (Another good reason to use a script!)
There may be a better way than what I’m doing above, but it works for me, so I’m not going to bother looking for another way. Hope this helps!