Hi list, I'm trying to do something to make rc.conf can act conditionally What I want is: 1. List the wireless access points, grep if there is one which bssid is 'bb:bb:bb:bb:bb:bb', if there is, then set ifconfig_wlan0 to the value: "inet 192.168.1.111 netmask 255.255.255.0 WPA" 2. check if bitlbee has been installed, if so, then let bitlbee service start. So I tried with following settings in rc.conf, but all of them failed, i.e., the networking can't be connected and bitlbee service doesn't run. /etc/rc.conf if ifconfig wlan0 list scan 2>/dev/null | grep -q 'bb:bb:bb:bb:bb:bb' >/dev/null 2>&1; then ifconfig_wlan0="inet 192.168.1.111 netmask 255.255.255.0 WPA" fi if [ -x /usr/local/sbin/bitlbee ]; then bitlbee_enable="YES" fi My question is, how to achieve what I want? The simpler, the better :) -- Regards, Yue Wu Key Laboratory of Modern Chinese Medicines Department of Traditional Chinese Medicine China Pharmaceutical University No.24, Tongjia Xiang Street, Nanjing 210009, China
On Tue, Feb 01, 2011 at 08:35:06PM +0800, Yue Wu wrote:> Hi list, > > I'm trying to do something to make rc.conf can act conditionally > > What I want is: > > 1. List the wireless access points, > > grep if there is one which bssid is 'bb:bb:bb:bb:bb:bb', > > if there is, then set ifconfig_wlan0 to the value: > > "inet 192.168.1.111 netmask 255.255.255.0 WPA" > > 2. check if bitlbee has been installed, if so, then let bitlbee > service start. > > > So I tried with following settings in rc.conf, but all of them failed, > i.e., the networking can't be connected and bitlbee service doesn't > run. > > /etc/rc.conf > > if ifconfig wlan0 list scan 2>/dev/null | grep -q 'bb:bb:bb:bb:bb:bb' >/dev/null 2>&1; then > ifconfig_wlan0="inet 192.168.1.111 netmask 255.255.255.0 WPA" > fi > if [ -x /usr/local/sbin/bitlbee ]; then > bitlbee_enable="YES" > fi/etc/rc.conf is scriptable (unless you are also using a dashboard or other software that wants to interpret/update /etc/rc.conf). Your problem here is that rc.conf is read (and executed) before wlan0 gets created. After creation of an interface, /etc/start_if.<interface> is called, perhaps you could use that but keep in mind it's run just after creation of the interface so if you use it for wlan0 and need the output of a station scan you should use ifconfig wlan0 scan instead of ifconfig wlan0 list scan. This may take some time during which your boot process is stalled.> My question is, how to achieve what I want? The simpler, the better :)Otherwise, perhaps devd could help you to run your script asynchronously after wlan0 is created. Regards, Paul Schenkeveld
On 01/02/2011 13:35, Yue Wu wrote:> Hi list, > > I'm trying to do something to make rc.conf can act conditionallyTechnically, yes it can be done, but you shouldn't. It is in essence a shell script as it is sourced by other shell scripts but that's only because that approach is easiest to implement. Other tools may read rc.conf and they could break if they find something unexpected there.
Quoting Yue Wu <vanopen@gmail.com> (from Tue, 1 Feb 2011 20:35:06 +0800):> 2. check if bitlbee has been installed, if so, then let bitlbee > service start. > > > So I tried with following settings in rc.conf, but all of them failed, > i.e., the networking can't be connected and bitlbee service doesn't > run. > > /etc/rc.conf> if [ -x /usr/local/sbin/bitlbee ]; then > bitlbee_enable="YES" > fiIf it is not installed, there will be no rc.d script for it, so nothing will happen. This means you just can add bitlbee_enable="YES" unconditionally, and no error/warning message will show up during boot. Bye, Alexander. -- There's no time like the present for postponing what you don't want to do. http://www.Leidinger.net Alexander @ Leidinger.net: PGP ID = B0063FE7 http://www.FreeBSD.org netchild @ FreeBSD.org : PGP ID = 72077137
On 2/1/11 1:35 PM, Yue Wu wrote:> Hi list, > > I'm trying to do something to make rc.conf can act conditionally > > What I want is: > > 1. List the wireless access points, > > grep if there is one which bssid is 'bb:bb:bb:bb:bb:bb', > > if there is, then set ifconfig_wlan0 to the value: > > "inet 192.168.1.111 netmask 255.255.255.0 WPA" > > 2. check if bitlbee has been installed, if so, then let bitlbee > service start. > > > So I tried with following settings in rc.conf, but all of them failed, > i.e., the networking can't be connected and bitlbee service doesn't > run. > > /etc/rc.conf > > if ifconfig wlan0 list scan 2>/dev/null | grep -q 'bb:bb:bb:bb:bb:bb' >/dev/null 2>&1; then > ifconfig_wlan0="inet 192.168.1.111 netmask 255.255.255.0 WPA" > fi > if [ -x /usr/local/sbin/bitlbee ]; then > bitlbee_enable="YES" > fi > > My question is, how to achieve what I want? The simpler, the better :) >You may want to call an external script directly from rc.local instead, to avoid breaking stuff that parses rc.conf Never know ;) It's not like rc.conf is a totally critical file that will break your startup if you mess it up...