Stefan Monnier wrote:
When I'm AC-plugged, I like my /etc/init.d/network script to start my wifi card automatically. But when I'm on battery, I'd rather not start it automatically (I can always start it manually if I really want it). Does anybody have an idea how to do that? Can the `auto' lines in /etc/network/interfaces be parameterized by a little script that says whether or not to auto-config the interface at boot?
I do something like this. The problem I wanted to solve was that I didn't want the wireless interface to be activated when the wired interface was already up. I added a pre-up line in my interfaces file. Here's the section that defines my wireless card:
iface eth-wlan inet dhcp pre-up [ -z "$(ifconfig eth-lan | grep 'inet addr:')" ] && true pre-up /sbin/iwconfig eth-wlan essid <ESSID snipped> pre-up /sbin/iwconfig eth-wlan enc on pre-up /sbin/iwconfig eth-wlan key <MY KEY snipped>My wired interface is named "eth-lan" and the wireless "eth-wlan", BTW. So that first line checks to see if eth-lan has an IP address or not. If it does not have an IP, then the line returns true and the interface is allowed to come up. If eth-lan does have an IP, it will return false and the eth-wlan interface will fail when attempting to come up.
Honestly, I'm not 100% sure why I have the "&& true" bit on there. It might not be necessary.
Anyway, if you can provide a set of commands (or a script) that can detect when you're AC plugged, you should be able to do something similar.
Thanks, Rick Reynolds --Time is nature's way of keeping everything from happening at once. -- Woody Allen