The Following 2 Users Say Thank You to Matan For This Useful Post: | ||
|
2010-01-23
, 03:06
|
|
Posts: 139 |
Thanked: 135 times |
Joined on Jan 2010
@ Cambridgeshire, UK
|
#42
|
#!/bin/sh logentry() { #SEND A STRING TO THIS FUNCTION TO APPEND IT TO THE LOG FILE echo -e "$1" >> /home/user/MyDocs/tmp/autoDCscriptLOG.txt } osnotify() { #SEND A STRING TO THIS FUNCTION TO GENERATE A SYSTEM POPUP run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"$1" } #PREPARE INITIAL VARIABLES FOR TEMPORAL MONITORING OF NETWORK INTERFACES getcell=`ifconfig phonet0 | grep RX.p | cut -d: -f2` getwifi=`ifconfig wlan0 | grep RX.p | cut -d: -f2` bakcell=$getcell bakwifi=$getwifi getcellup=`ifconfig | grep gprs0 | cut -d: -f0` getwifiup=`ifconfig wlan0 | grep inet.addr | cut -d: -f2` #LOG MONITOR STARTUP TO FILE & NOTIFY USER VIA POPUP logentry "\nIdle Monitor Startup $(date)\nEVENTS:\n" osnotify "Automatic internet disconnection monitor has started" #PERFORM MAIN MONITORING LOOPS while true ; do #CHANGE THE NUMBER AFTER SLEEP TO SET THE NUMBER OF SECONDS BEFORE #THE INTERNET IS DISCONNECTED IF NO INTERNET ACTIVITY IS DETECTED sleep 300 getcell=`ifconfig phonet0 | grep RX.p | cut -d: -f2` getwifi=`ifconfig wlan0 | grep RX.p | cut -d: -f2` getcellup=`ifconfig | grep gprs0 | cut -d: -f0` getwifiup=`ifconfig wlan0 | grep inet.addr | cut -d: -f1` if [ -n "$getcellup" -o -n "$getwifiup" ]; then #IF EITHER NETWORK INTERFACE HAS AN IP PROCEED WITH INACTIVITY TEST if [ "$getcell" == "$bakcell" -a "$getwifi" == "$bakwifi" ]; then #IF NO PACKETS WERE RECEIVED SINCE LAST RECORDING THEN SHUTDOWN INTERFACES dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true if [ -n "$getcellup" ]; then osnotify "The 2G/3G internet connection has been closed due to inactivity" logentry " - 2G/3G DISCONNECTED @ $(date)" elif [ -n "$getwifiup" ]; then osnotify "The WI-FI internet connection has been closed due to inactivity" logentry " - WI-FI DISCONNECTED @ $(date)" else osnotify "The internet connection has been closed due to inactivity" logentry " - ????? DISCONNECTED @ $(date)" fi fi bakcell=$getcell bakwifi=$getwifi fi done exit
|
2010-01-23
, 09:08
|
Posts: 1,224 |
Thanked: 1,763 times |
Joined on Jul 2007
|
#43
|
The Following User Says Thank You to Matan For This Useful Post: | ||
|
2010-01-24
, 04:35
|
Posts: 5 |
Thanked: 0 times |
Joined on Jan 2010
|
#44
|
|
2010-01-24
, 10:01
|
Posts: 69 |
Thanked: 55 times |
Joined on Nov 2009
|
#45
|
I've spent some time on this script and refined it a little:
*It now only does anything if there's an active connection.
*It logs startup and disconnections to a file in mydocs/tmp
*It notifies you onscreen when disconnecting
*It distinguishes between wifi/cellular connections
I still cannot get it to autostart though - I don't get what I'm doing wrong. I have an entry in /etc/event.d as suggested and have tried everything I can see - to no avail. Ideally it needs to start once the desktop is up and loaded properly... any ideas anyone?
Here's my script for anyone who wants it
Code:#!/bin/sh logentry() { #SEND A STRING TO THIS FUNCTION TO APPEND IT TO THE LOG FILE echo -e "$1" >> /home/user/MyDocs/tmp/autoDCscriptLOG.txt } osnotify() { #SEND A STRING TO THIS FUNCTION TO GENERATE A SYSTEM POPUP run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"$1" } #PREPARE INITIAL VARIABLES FOR TEMPORAL MONITORING OF NETWORK INTERFACES getcell=`ifconfig phonet0 | grep RX.p | cut -d: -f2` getwifi=`ifconfig wlan0 | grep RX.p | cut -d: -f2` bakcell=$getcell bakwifi=$getwifi getcellup=`ifconfig | grep gprs0 | cut -d: -f0` getwifiup=`ifconfig wlan0 | grep inet.addr | cut -d: -f2` #LOG MONITOR STARTUP TO FILE & NOTIFY USER VIA POPUP logentry "\nIdle Monitor Startup $(date)\nEVENTS:\n" osnotify "Automatic internet disconnection monitor has started" #PERFORM MAIN MONITORING LOOPS while true ; do #CHANGE THE NUMBER AFTER SLEEP TO SET THE NUMBER OF SECONDS BEFORE #THE INTERNET IS DISCONNECTED IF NO INTERNET ACTIVITY IS DETECTED sleep 300 getcell=`ifconfig phonet0 | grep RX.p | cut -d: -f2` getwifi=`ifconfig wlan0 | grep RX.p | cut -d: -f2` getcellup=`ifconfig | grep gprs0 | cut -d: -f0` getwifiup=`ifconfig wlan0 | grep inet.addr | cut -d: -f1` if [ -n "$getcellup" -o -n "$getwifiup" ]; then #IF EITHER NETWORK INTERFACE HAS AN IP PROCEED WITH INACTIVITY TEST if [ "$getcell" == "$bakcell" -a "$getwifi" == "$bakwifi" ]; then #IF NO PACKETS WERE RECEIVED SINCE LAST RECORDING THEN SHUTDOWN INTERFACES dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true if [ -n "$getcellup" ]; then osnotify "The 2G/3G internet connection has been closed due to inactivity" logentry " - 2G/3G DISCONNECTED @ $(date)" elif [ -n "$getwifiup" ]; then osnotify "The WI-FI internet connection has been closed due to inactivity" logentry " - WI-FI DISCONNECTED @ $(date)" else osnotify "The internet connection has been closed due to inactivity" logentry " - ????? DISCONNECTED @ $(date)" fi fi bakcell=$getcell bakwifi=$getwifi fi done exit
|
2010-01-24
, 15:16
|
|
Posts: 139 |
Thanked: 135 times |
Joined on Jan 2010
@ Cambridgeshire, UK
|
#46
|
|
2010-01-28
, 10:25
|
Posts: 5 |
Thanked: 3 times |
Joined on Jan 2010
@ Isle of Man
|
#47
|
|
2010-01-28
, 11:08
|
|
Posts: 139 |
Thanked: 135 times |
Joined on Jan 2010
@ Cambridgeshire, UK
|
#48
|
You would probably do better to use transmitted rather than received packets because most networks will have some general chatter on them even if they are only occasional broadcast messages and those packet could keep your network connection up even if you aren't responding to them.
Perhaps the best solution is actually to check if both RX and TX have changed?
The Following User Says Thank You to stopgap For This Useful Post: | ||
|
2010-01-28
, 14:49
|
Posts: 5 |
Thanked: 3 times |
Joined on Jan 2010
@ Isle of Man
|
#49
|
The Following 2 Users Say Thank You to farnwomt For This Useful Post: | ||
|
2010-01-28
, 18:58
|
Posts: 17 |
Thanked: 0 times |
Joined on Dec 2009
@ Honolulou
|
#50
|
|
Replace $1 with your message.
But this is the type that does not go automatically.
Replace SystemNoteDialog with SystemNoteInfoprint and don't include the last uint32:0 string:'NAO OK!'
My repository
"N900 community support for the MeeGo-Harmattan" Is the new "Mer is Fremantle for N810".
No more Nokia devices for me.