Active Topics

 


Reply
Thread Tools
Posts: 31 | Thanked: 44 times | Joined on Nov 2009 @ Czech Republic
#91
Originally Posted by Matan View Post
This script should disconnect from network (wlan or GPRS/UMTS) after 5 to 10 minutes of no received packets:

Code:
#!/bin/sh
a=`ifconfig phonet0 | grep RX.p | cut -d: -f2`
c=`ifconfig wlan0 | grep RX.p | cut -d: -f2`
b=$a
d=$c

while true ; do
        sleep 300
        a=`ifconfig phonet0 | grep RX.p | cut -d: -f2`
        c=`ifconfig wlan0 | grep RX.p | cut -d: -f2`
        if [ "$a" == "$b" -a "$c" == "$d" ] ; then
                dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
        fi
        b=$a
        d=$c
done
I replaced phonet0 with gprs0 and set it the timeout to 180 seconds and it works great!
__________________
OpenWatch - Bluetooth watch support in Maemo
 
Posts: 43 | Thanked: 32 times | Joined on Jan 2010
#92
Originally Posted by moneytoo View Post
I replaced phonet0 with gprs0 and set it the timeout to 180 seconds and it works great!
Are you sure that it works? Let's asume you are connected to internet via wi-fi and the connection is idle (since I don't use gprs I will ignore it here but my point should still stand... unless for gprs you actually don't receive any packets while being idle). If you input

Code:
ifconfig wlan0 | grep RX.p | cut -d: -f2
as a normal user into the terminal you get the following:

Code:
-sh: ifconfig: not found
If you run that script as a whole as a normal user you get something like (not exactly): error line 2: ifconfig: not found and error line 3: ifconfig not found and it would disconnect you after 5 mins even if you were using the internet.

Get connected again.

Now, gain root and type:

Code:
ifconfig wlan0 | grep RX.p | cut -d: -f2
You'll see that this time it does work.

If you run the script as root you don't get any errors but you also don't get disconnected. To find out why, open another terminal and run (as root).

Code:
ifconfig wlan0 | grep RX.p | cut -d: -f2
Wait about 60-120 seconds and do it again. The values are different, aren't they? Even though you aren't using the connection. Since these values are different. The script doesn't disconnect you.
 
Posts: 43 | Thanked: 32 times | Joined on Jan 2010
#93
Originally Posted by jmk View Post
Could someone do 3G compatible version of this. Change wlan0>gprs0 etc. and edit cuts?

Maybe this script should run only when connected like this /etc/networks/if-pre-up.d/ or /etc/networks/if-up.d/
to start every time a network interface is upped.

And someone should make simple control panel applet to turn this script on/off. Like wifi-switcher check the source code.
Do you want to test my script? I'm not entirely sure about it being 3G compatible but it should work. Run it from terminal first to see if it works (if you can, test it with 2g, 3g and wi-fi). If it works, change the first two sleep to 180 (or any number that you may like... I just like 180) and erase all the "echo"s. If it doesn't work, please paste here the outcomes of the script.

Code:
#!/bin/sh
while true; do
      sleep 180
      a=`tail -1 /proc/net/route | cut -f1`
      while [ "$a" != "Iface" ]
      do
            b=`ifconfig wlan0 | grep RX.p | cut -d"(" -f1 | cut -d: -f2`
            c=`expr $b + 1000`
            sleep 180
            b=`ifconfig wlan0 | grep RX.p | cut -d"(" -f1 | cut -d: -f2`
            a=`tail -1 /proc/net/route | cut -f1`
            if [ "$b" -lt "$c" -a "$a" != "Iface" ]; then
                  dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true 
                  sleep 10
                  a=`tail -1 /proc/net/route | cut -f1`
            fi
      done
done
I wasn't able to add any file to /etc/networks/if-pre-up.d/ or /etc/networks/if-up.d/ so I could'nt make it start like you suggested. However, I believe that it may be possible to change the contents in /etc/event.d/autodisconnect to start when a connection is established and stop when the connection is lost. Even so, I lack knowledge about that.

Last edited by azstunt; 2010-02-09 at 16:45.
 
Posts: 241 | Thanked: 69 times | Joined on Dec 2009 @ Germany
#94
@azstund,

I tested your modified script and at first after bootup it disconnected me correctly. Then I tested if it leaves a used connection unchanged by listening to internet radio streams. The script did not disconnect, fine. Afterwards i closed all programs causing traffic and waited for a disconnect, but nothing happens.

Can you figure out whats wrong?
 
Posts: 18 | Thanked: 14 times | Joined on Jan 2010
#95
I would rather attach it to the cron: http://talk.maemo.org/showthread.php?p=467732 with 3 minutes period instead of global while true...
 
Posts: 43 | Thanked: 32 times | Joined on Jan 2010
#96
Originally Posted by raily View Post
@azstund,

I tested your modified script and at first after bootup it disconnected me correctly. Then I tested if it leaves a used connection unchanged by listening to internet radio streams. The script did not disconnect, fine. Afterwards i closed all programs causing traffic and waited for a disconnect, but nothing happens.

Can you figure out whats wrong?
Were you using 3g, 2g or wi-fi? Would you mind reproducing it in the terminal (with all the echos that I have above) and pasting here the outcomes, please?

EDIT: Another thing, what time did you set for sleep and how much time did you wait for a disconnection after closing all programs?

Last edited by azstunt; 2010-02-08 at 13:24.
 
Posts: 43 | Thanked: 32 times | Joined on Jan 2010
#97
Originally Posted by raily View Post
@azstund,

I tested your modified script and at first after bootup it disconnected me correctly. Then I tested if it leaves a used connection unchanged by listening to internet radio streams. The script did not disconnect, fine. Afterwards i closed all programs causing traffic and waited for a disconnect, but nothing happens.

Can you figure out whats wrong?
Disregard my last reply. I have made more changes to the script up here (post # 93). Please check them out and use that script.
 
Posts: 241 | Thanked: 69 times | Joined on Dec 2009 @ Germany
#98
ok, good I was to lazy yesterday to set up the test
But is you Script in post #93 affecting packet connection over 3G, GPRS? I just want to disconnect WLAN, hence I don't think I can idle in ICQ when on 3G anymore if I use Script #93.
 
Posts: 173 | Thanked: 160 times | Joined on Jan 2010 @ London, UK
#99
I wrote a script for /etc/network/if-up.d/ a number of weeks back to check whether the slide was shut, whether ssh was running (rarely want disconnect in this case) and if so, disconnect. It exited if no route was up. Sorting idled bytes xfered was the missing piece, thanks for this thread! I can post my script if ppl are interested.
 
Posts: 17 | Thanked: 14 times | Joined on Jan 2010 @ London, UK
#100
Originally Posted by damion View Post
I wrote a script for /etc/network/if-up.d/ a number of weeks back to check whether the slide was shut, whether ssh was running (rarely want disconnect in this case) and if so, disconnect. It exited if no route was up. Sorting idled bytes xfered was the missing piece, thanks for this thread! I can post my script if ppl are interested.
This sounds really useful, I for one would like to see it.

Also, when I connect to a network the email app automatically checks for new emails. If the script could also automatically bring an interface up intermittently (then normal logic to bring it down) would email be checked? This would be perfect - long battery life plus email notifications.

I would also like to be able to bring down openvpn when on my home wifi connection. It looks like this thread might make this possible too...
 
Reply

Tags
automatic, connect, connect automatically, connect on activity, connect on demand, connect on use, data, data connection, disconnect, disconnect automatically, disconnect when idle, fremantle, gprs, internet, maemo, maemo 5, n900, on demand, on use


 
Forum Jump


All times are GMT. The time now is 22:47.