Shell script should switch if connection established but doesn't
I have created the following script
Code:
#!/bin/sh Today I found another output which makes no sense: Fri Jan 8 16:38:30 GMT-11 2010 - gprs0 wlan0 WLAN_INFRA Fri Jan 8 16:38:50 GMT-11 2010 - gprs0 wlan0 WLAN_INFRA Fri Jan 8 16:38:50 GMT-11 2010 - No interface found! I wonder why the script doesn't work because wlan0 is correct and should be identified as it is. And also why do I have the output lines without a date (wlan0 WLAN_INFRA)? I don't have them added to the script and the "Fri Jan 8 16:38:50 GMT-11 2010 - gprs0" line is wrong because the connection changed to WLAN at this time. The script runs on a Nokia N900 with Busybox ("small Debian"). Thanks for help. |
I think, may be some IP was resolved like WLAN_INFRA, and instead to write IP address like 192.xxx.xxx.xxx it saves WLAN_INFRA.
|
Do you know a better way to get the status of wlan0? I want to use this script to toggle my online status of a VoIP account because I only want to be online with VoIP when I am on a WiFi connection...
|
Do you have command: iwconfig wlan0?
|
No, only ifconfig wlan0
|
Quote:
|
A reliable way to determine if wlan0 is active (and maybe has an internet connection).
|
I don't know exactly for Nokia, but if you are connected to AP somewhere has to be written its AP ESSID and when you are disconnected instead of MAC AP there is "Not Associated" (in linux). So if you know Nokia OS well you can search for that sentence.
I hope it helps. |
Thanks I will try that.
You were wrong in your first answer: "wlan0 WLAN_INFRA" is the output of "echo $interface $ICD_CONNECTION_TYPE" ($ICD_CONNECTION_TYPE is a global variable) and the strange thing is that I don't have a line like that in the script and at the same time the output of the line "echo $(date) - $interface $ICD_CONNECTION_TYPE" is "Fri Jan 8 16:38:30 GMT-11 2010 - gprs0 " which means that "$interface" is equal to "gprs0" and "$ICD_CONNECTION_TYPE" is empty. Do you know what the problem could be? |
Have a look:
http://stefans.datenbruch.de/nokia770/ |
Thanks but I don't want wo have a daemon running all the time which waits for a special DBUS signal. I want to use a script in /etc/network/if-up.d/ because this will be executed every time a connection changes. As I mentioned before the "WLAN_INFRA" output is not reliable and because of that I have created my own variable "interface=`ifconfig | grep -iE "(wlan0|gprs0)" | awk '{print $1}'`" which is reliable but the rest of the script in my first post reacts strange sometimes if you look at my example and I would like to know how to solve this.
|
Tell,please, what is the full output you get for "ifconfig", when you are connected through wifi and gprs.
Connect with wifi and execute "ifconfig" (just ifconfig without anything) Connect with gprs and do the same. Post output here, if it is not a secret. |
GPRS active:
Quote:
Quote:
|
So, "ifconfig" by it self without additional arguments gives information ONLY about active interfaces.
If you will just parse "ifconfig" output, you will get exactly what you want, it will be only wlan1|gprs in it output. |
Yeah I know. I have done that already. Look at the second line in my first post:
interface=`ifconfig | grep -iE "(wlan0|gprs0)" | awk '{print $1}'` But something in the script is not reliable because sometimes I can see the following in the logs: Quote:
Do you know what I mean and how I can solve it? |
All times are GMT -5. The time now is 12:50 AM. |