
NetworkManager Dispatcher
NetworkManager is Red Hat's "networking made easy" utility that allows UNIX-like OSes to "do the right thing" most of the time when dealing with networks. But what if you want to do something else?
At the TLT Media Lab at Stony Brook we are working on a system that automatically records a lecture, both the chalkboards and the presentation computer display, on a particular schedule and puts those recordings online. The computer that will sit in the classroom and do the actual recording is to be headless so it needs to tell the scheduling/hosting server when it receives an IP from the DHCP server. So, how do we make the recording computer contact the scheduling server when it is assigned an IP? NetworkManager dispatcher!
Reading Justin Ellison's post on SysAdmin's Journey gave me the idea. He used NetworkManager dispatcher to make synergy automatically load up when he connects to his work network. We only need to contact the scheduling server when our network comes up. So in our distribution (Ubuntu) the dispatcher scripts go in /etc/NetworkManager/dispatcher.d/ where we make a script "99alert_scheduler.sh":
1. #!/bin/sh
2.
3. IF=$1 # The interface calling the status update
4. STATUS=$2 # The new status of the interface, up or down
5
6. if [ "$IF" = "eth0" ] && [ "$STATUS" = "up" ]; then
7.
8. # Get our IP
9. IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' |cut -d: -f2 | awk '{ print $1}'`
10.
11. # Use wget to communicate our IP, get server response in a variable
12. RESPONSE=`wget http://nicholaswellcome.com/get?ip=$IP 2>&1`
13.
14. fiThat's it for now, we will want to set up a job to try to connect later if we get an error back from the server or if wget can't connect - but at the moment the scheduling server does not exist (also not the point of this post). What I hope you get from this is those first 6 lines above because it took me too long to find out that scripting network behavior in Linux was this easy.

Nicholas Wellcome is a software engineer fresh out of grad school and newly relocated in Boston, MA 



Comments
20 March 2011
1 year 5 weeks
Team usa basketball jerseys receptionist ignobly Who makes vimax Civet raucously Volume Pills sanctum hypertension