![]() |
2010-02-11
, 21:00
|
Posts: 5 |
Thanked: 0 times |
Joined on Jan 2010
|
#121
|
![]() |
2010-02-11
, 21:33
|
Posts: 17 |
Thanked: 14 times |
Joined on Jan 2010
@ London, UK
|
#122
|
![]() |
2010-02-11
, 22:19
|
Posts: 43 |
Thanked: 32 times |
Joined on Jan 2010
|
#123
|
Hey mclarson!
Thanks for the merge! The script begins to be pretty clean now. I will use it in the application.
I've got a few questions :
1) Why have you chosen to keep the 2 while instructions ? -> See my script with only 1 while
2) Why have you chosen to read the RX instead of the TX value ?
3) Number of bytes to ignore for each time period : where does it come from in fact ? Broadcast ? I ask because in my tests on my device, neither the 3G nor the WLAN connexion have generated transmitted packets when I was connected with no activity. But in my case I read TX value and not the RX value.
Thanks!
![]() |
2010-02-12
, 03:33
|
|
Posts: 286 |
Thanked: 219 times |
Joined on Feb 2010
@ France
|
#124
|
Interesting. I agreed with azstunt's detection method but did not think too hard about it as it felt right. Conversely I find it hard to believe there are no TX packets - what about email checks, weather updates or whatever..
For a bulk download relativey tiny ACKS would be sent, ie tiny sample, but would have lots of rx, ie big sample. My *idle* connection does about 2k per minute - there /must/ be tx in there but I've not checked what that traffic is.
![]() |
2010-02-12
, 03:45
|
|
Posts: 286 |
Thanked: 219 times |
Joined on Feb 2010
@ France
|
#125
|
It may be wrong for me to answer but since most of the operational code of mclarson seems to be derivated from mine, I'll answer point 3. Put bluntly, your script doesn't fully work for me. When using my wi-fi at home the n900 receives 1 packet of 42 bytes or so every 20 (aprox) seconds. I've tested other 2 wi-fi spots and got another similar situation and another one where I don't receive any packets (and your script would work). Same configuration in the device. That's why I decided to use a small amount of bytes to asure the connection is idle and those are random packets.
![]() |
2010-02-12
, 12:39
|
Posts: 8 |
Thanked: 0 times |
Joined on Feb 2010
@ Netherlands
|
#126
|
![]() |
2010-02-12
, 13:19
|
Posts: 17 |
Thanked: 14 times |
Joined on Jan 2010
@ London, UK
|
#127
|
The Following 2 Users Say Thank You to mclarson For This Useful Post: | ||
![]() |
2010-02-12
, 13:28
|
Posts: 17 |
Thanked: 14 times |
Joined on Jan 2010
@ London, UK
|
#128
|
The Following User Says Thank You to mclarson For This Useful Post: | ||
![]() |
2010-02-12
, 13:37
|
Posts: 52 |
Thanked: 10 times |
Joined on Jan 2010
@ London, UK
|
#129
|
I've merged the scripts from azstunt and calvin_42 since they both have great features - I like the visual notification for starting connection monitoring and ending a connection. if-up was a good choice too.
Seems to work quite well. Instructions for install pretty much as azstunt says. Read the comments...
/usr/local/bin/autodisconnect:
/etc/network/if-up.d/99_autodisconnect:Code:#!/bin/sh # --------------------------------------------------------------------------- # MODIFY THESE PARAMETERS TO SUIT # --------------------------------------------------------------------------- # How often to test for inactivity g_samplerate=90 # If only a few bytes are received you may still want to disconnect. # Specify the number of bytes per minute here. g_dontcountbytespermin=5000 # Don't auto disconnect for the listed interfaces in g_disable # Effectively disables this script: #g_disable="wlan gprs" # Disable for gprs: #g_disable="gprs" # Disable for wlan: #g_disable="wlan" # Disconnect enabled for wlan and gprs: g_disable= # Enable logging #g_logging="true" g_logging="false" # Where to store the logfile. This is cleared when it goes over 100k. logfile=/root/autodisconnect.log # --------------------------------------------------------------------------- # DON'T MODIFY ANYTHING BELOW THIS POINT # --------------------------------------------------------------------------- # --------------------------------------------------------------------------- # GLOBALS # --------------------------------------------------------------------------- # Never drop openvpn. Iface is just a heading therefore not real. g_disable="Iface tun "$g_disable # Number of bytes to ignore for each time period g_dontcountbytes=$((g_dontcountbytespermin*g_samplerate/60)) # --------------------------------------------------------------------------- # FUNCTIONS # --------------------------------------------------------------------------- # --------------------------------------------------------------------------- init() # --------------------------------------------------------------------------- { # Allow dbus to work [[ -e /tmp/dbus-info ]] && eval `cat /tmp/dbus-info` export DBUS_SESSION_BUS_ADDRESS \ DBUS_SESSION_BUS_PID \ DBUS_SESSION_BUS_WINDOWID # Don't let log file get too big if [[ -w "$logfile" ]]; then size=`stat $logfile | grep Size | awk '{ print $2; }'` [[ "$size" -gt 100000 ]] && :>$logfile fi } # --------------------------------------------------------------------------- logentry() # --------------------------------------------------------------------------- # Send a string to this function to append it to the log file # # Arg 1 - The text to log { [[ "$g_logging" == "true" ]] && { echo -e "`date` $1" >> $logfile echo "`date` $1" } } # --------------------------------------------------------------------------- osnotify() # --------------------------------------------------------------------------- # Send a string to this function to generate a system popup # # Arg 1 - The text to display { /usr/bin/dbus-send --type=method_call \ --dest=org.freedesktop.Notifications \ /org/freedesktop/Notifications \ org.freedesktop.Notifications.SystemNoteInfoprint \ string:"$1" } # --------------------------------------------------------------------------- disconnect() # --------------------------------------------------------------------------- # Disconnect current connection # # No args { dbus-send --system --dest=com.nokia.icd \ /com/nokia/icd_ui \ com.nokia.icd_ui.disconnect \ boolean:true } # --------------------------------------------------------------------------- disable_quit() # --------------------------------------------------------------------------- { # Disable for some interfaces [[ -n "$g_disable" ]] && { if echo "$g_disable" | grep -qs "$interface" 2>/dev/null; then #osnotify "Auto-disconnect disabled for $interface" logentry "Auto-disconnect disabled for $interface" exit 0 else osnotify "Auto-disconnect enabled for $interface" logentry "Auto-disconnect enabled for $interface" fi } } # --------------------------------------------------------------------------- main() # --------------------------------------------------------------------------- # Main entry point { init # Log monitor startup to file & notify user via popup logentry "Auto-disconnect starting" interface=`grep -v tun /proc/net/route | tail -1 | cut -f1 | tr -d 0-9` logentry "Current connection : $interface" # Quit if this interface is in the g_disable list disable_quit while true; do sleep $g_samplerate a=`grep -v tun /proc/net/route | tail -1 |cut -f1` while [[ "$a" != "Iface" ]]; do b=`ifconfig $a | grep RX.b | cut -d"(" -f1 | cut -d: -f2` c=$b sleep $g_samplerate b=`ifconfig $a | grep RX.b | cut -d"(" -f1 | cut -d: -f2` a=`grep -v tun /proc/net/route | tail -1 |cut -f1` if [ "$a" == "Iface" ]; then osnotify "Auto-disconnect for $interface stopped." logentry "$interface lost. Quitting." exit 0 fi if [ "$b" -lt "$((c+g_dontcountbytes))" -a "$a" != "Iface" ]; then disconnect osnotify "Connection $interface closed due to inactivity" logentry "$interface closed. Bytes received : $((b-c))" exit 0 else logentry "$interface: Bytes received : $((b-c))" fi done done } # Start main exit 0
/etc/network/if-down.d/99_autodisconnect:Code:#!/bin/sh AUTODISCONNECT=/usr/local/bin/autodisconnect if [ ! -x $AUTODISCONNECT ]; then exit 0 fi $AUTODISCONNECT
Enjoy!Code:#!/bin/sh AUTODISCONNECT=/usr/local/bin/autodisconnect if [ ! -x $AUTODISCONNECT ]; then exit 0 fi kill `pidof autodisconnect`
![]() |
2010-02-12
, 17:06
|
|
Posts: 286 |
Thanked: 219 times |
Joined on Feb 2010
@ France
|
#130
|
The Following User Says Thank You to calvin_42 For This Useful Post: | ||
![]() |
Thread Tools | |
|