Shell redirection Debugging information
Fulinux
*************************************************************************************************************** ***********************
Author: fulinux
Reprint statement: http://blog.csdn.net/fulinus/article/details/29912333
*************************************************************************************************************** ***********************
Background: When porting WiFi, you want to be able to access it via WiFi when you start, mainly through scripting. Run the/etc/inittab script on startup, then call the/etc/init.d/rcs script, and the RCS script will run the script file that starts with sxx in the/etc/init.d/folder, where the S01_network script file is what we need. The S01_network script section contains the following examples:
#!/bin/sh# File:/etc/init.d/s01_network.。
If [-d/sys/class/net/$DEVICE/]; Then /apps/tools/ifup-wlan $i route del default dev eth0 route add default GW 192.168.1.1 fi ...
The s01_network script invokes the/apps/tools/ifup-wlan script.
The Ifup-wlan script section contains the following examples:
#!/bin/sh# File:/usr/sbin/ifup-wlan0.。 #Start wpa_supplicant to work now mkdir-p/var/run/wpa_supplicant /apps/tools/wpa_supplicant-b-dwext-i $DEVICE-c${network_cfg_dir}/wpa_supplicant.conf.
。
。
can say that all of the above scripts are not wrong, because I run the RCS script directly after the normal operation of all the subsequent scripts, after running a normal connection to the WiFi router, such as the following:
[[email protected]/ETC/INIT.D] #iwconfig wlan0wlan0 IEEE 802.11bg ESSID: "fulinus" Mode: Managed frequency:2.437 GHz Access point:94:0c:6d:4f:bd:c8 Bit rate=1 mb/s tx-power=20 dBm Retry long limit:7 RTS thr:off Fragment thr:off encryption Key:off Power Management:on Link quality=70/70 Signal level=-21 dBm Rx Invalid nwid:0 rx Invalid crypt:0 Rx invalid frag:0 Tx excessive retries:0< C22/>invalid misc:0 Missed beacon:0
But there was a problem. Power-on does not enable WiFi access. After booting I found that there was no connection to the WiFi router at all. For example, the following:
[[Email protected] ~] #iwconfig wlan0wlan0 IEEE 802.11bg essid:off/any mode:managed Access point: not-associated tx-power=20 dBm Retry long limit:7 RTS thr:off Fragment thr:off Encryption Key:off Power Management:on
This is very strange. The problem is not easy to find. So under the advice of Guo Gong I started debugging information by redirecting the print script.
The first step. Locate the S01_network script. Look at the problem is not here, so I at S01_network script start position and end position added such as the following settings:
#!/bin/sh ... set-x#脚本的主要内容set +x.。。
Also add the following red color settings to the RCS file:
#!/bin/shIF [!-F "/var/log/rcs.log"]; then touch/var/log/rcs.logfifor i in/etc/init.d/s??* ; Do >>/var/log/rcs.log 2>&1 Done
after startup we see the following information in the/var/log/rcs.log log file, for example:
[[email protected]/ETC/INIT.D] #cat/var/log/rcs.log + [!-F]+ touch/var/log/ifup-wlan.log+ Log=/var/log/ifup-wlan.log + [-Z]+ export network_cfg_dir=/etc/network+ cd/etc/network+ sed-e/ifcfg-[a-za-z0-9\._-]\+$/{s/^ifcfg-//g;s/[0-9]/ &/}+ ls ifcfg-wlan0+ sed s///+ sort-k 1,1-k 2n+ interfaces=wlan0+ ifconfig lo 127.0.0.1+ [-Z wlan0]+ unset Devic E type+ fgrep device= ifcfg-wlan0+ eval device=wlan0+ device=wlan0+ fgrep type= ifcfg-wlan0+ eval type=wlan+ TYPE=WLAN+ [ -Z wlan0]+ egrep-l ^onboot=[' "]? [Nn] [Oo] [‘"]?ifcfg-wlan0+ [WLAN = Ethernet]+ [WLAN = PPP]+ [WLAN = WLAN]+ [-d/sys/class/net/wlan0/]+/etc/network/ifup-wlan WL an0+ route del default dev eth0route:SIOCDELRT:No such process+ route add default GW 192.168.1.1+ set +x+ [!-F]+ Tou ch/var/log/ifup-wlan.log+ log=/var/log/ifup-wlan.log+ [-Z]+ export network_cfg_dir=/etc/network+ cd/etc/network+ ls i fcfg-wlan0+ sed-e/ifcfg-[a-za-z0-9\._-]\+$/{s/^ifcfg-//g;s/[0-9]/&/}+ sed s///+ sort-k 1,1-k 2n+ interfaces=wl an0+ ifconfig lo 127.0.0.1+ [-Z wlan0]+ unset DEVICE type+ fgrep device= ifcfg-wlan0+ eval device=wlan0+ device=wlan0+ F grep type= ifcfg-wlan0+ eval type=wlan+ type=wlan+ [-Z wlan0]+ egrep-l ^onboot=[' "]? [Nn] [Oo] [‘"]?
ifcfg-wlan0+ [WLAN = Ethernet]+ [WLAN = PPP]+ [WLAN = WLAN]+ [-d/sys/class/net/wlan0/]+/etc/network/ifup-wlan WL An0
did not find any problems.
The second step is to start locating the Ifup-wlan script file for problems. and made a similar change to the above.
#! /BIN/SHIF [!-F "$log"]; Then touch /var/log/ifup-wlan.log log=/var/log/ifup-wlan.logfi ... $network _cfg_dir/ifup-wlan $i >> ${log} 2>&1 ...
after starting to view the/var/log/ifup-wlan.log file, see information such as:
[[email protected]/etc/init.d] #cat/var/log/ifup-wlan.log ... +/apps/tools/wpa_supplicant-b-dwext-iwlan0-c/etc/network/wpa_supplicant.conf/apps/tools/wpa_supplicant:can ' t Load library 'libnl.so.1' ...
That is, when you run the Wpa_supplicant program, the Libnl.so.1 library file is not found. The problem is here.
So, I added the export discovery before/apps/tools/wpa_supplicant-b-dwext-iwlan0-c/etc/network/wpa_supplicant.conf this command:
Export export home= '/' Export oldpwd= '/etc/network ' export path= '/sbin:/usr/sbin:/bin:/usr/bin ' export pwd= '/etc/network ' Export shell= '/bin/sh ' export term= ' vt102 ' export user= ' root ' export network_cfg_dir= '/etc/network'/apps/ Tools/wpa_supplicant-b-dwext-iwlan0-c/etc/network/wpa_supplicant.conf/apps/tools/wpa_supplicant:can ' t load Library 'libnl.so.1'
This is not the same as the results I saw running the Export command on the terminal:
[[Email protected] ~] #exportexport dmalloc_options= ' debug=0x34f47d83,inter=100,log=logfile ' export editor= '/bin/vi ' export histfilesize= ' "Export histsize= '" Export home= '/' Export hostname= ' TQ2440 ' export inputrc= '/etc/inputrc ' export ld_library_ Path= '/apps/tslib/lib:/apps/lib ' export logname= ' root ' export pager= '/bin/more ' export path= '/bin:/sbin:/usr/bin:/ Usr/sbin:/usr/local/bin:/apps/bin:/apps/tools:/apps/tslib/bin: ' Export ps1= ' [\[email protected]\h \w]# ' Export PWD= ' /' Export qt_qws_fontdir= '/apps/lib/fonts ' export qws_mouse_proto= ' tslib:/dev/event1 ' export shell= '/bin/sh ' export term= ' vt100 ' export tslib_calibfile= '/etc/pointercal ' export tslib_conffile= '/apps/tslib/etc/ts.conf ' export tslib_ Consoledevice= ' None ' export tslib_plugindir= '/apps/tslib/lib/ts ' export tslib_root= '/apps/tslib ' export tslib_ Tsdevice= '/dev/event1 ' export user= ' root ' export var1= ' export var2= ' export var3= ' export var4= ' export var5= '
These environment variables are set in the profile file, originally when logged in. The init process will assign you a shell that will read the/etc/profile script as an environment variable. Therefore there will be no enable profile file without login.
Workaround:
Add red-colored statements to this location in the Ifup-wlan script.
export ld_library_path=/lib:/usr/lib: $TSLIB _root/lib:/apps/lib /apps/tools/wpa_supplicant-b-dwext-i$device-c${network_cfg_dir}/wpa_supplicant.conf
is to add the path of the missing LIBNL library to the environment variable in the library path.
Once run, WiFi is connected.
Shell redirection Debugging information