| View previous topic :: View next topic |
| Author |
Message |
serene LXF regular

Joined: Sun Jun 19, 2005 1:43 pm Posts: 101
|
Posted: Tue Mar 26, 2013 12:50 pm Post subject: Auto disconnect network after 20 minutes of inactivity |
|
|
Hi.
I wish to have my network disconnect after 20 minutes of inactivity.
I'm using the network-manager-gnome.
1. To determine if there are any network connections;
$ iptstate -1 -t | grep -c "Total States: 0"
0 = There are connections
1 = There are no connections
2. To disable the network;
$ nmcli nm enable false
It's been a while, my bash scripting is rusty.
Could someone please recommend a simple bash script I could run a cron job every 15-20 minutes that would check if there had been zero network activity so I can disable the network ?
Thank you.
Serene |
|
| Back to top |
|
 |
nelz Moderator

Joined: Mon Apr 04, 2005 12:52 pm Posts: 8036 Location: Warrington, UK
|
Posted: Tue Mar 26, 2013 2:39 pm Post subject: |
|
|
| Code: | | iptstate -1 -t | grep -q "Total States: 0" && nmcli nm enable false |
Provided iptstate shows details for all connections since the last run and not just the current time. _________________ "Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein) |
|
| Back to top |
|
 |
serene LXF regular

Joined: Sun Jun 19, 2005 1:43 pm Posts: 101
|
Posted: Wed Mar 27, 2013 12:07 pm Post subject: |
|
|
Thanks Nelz.
I didn't explain well enough.
Every 10 minutes, check for network activity...
if none, note.
Revisit 10 minutes later, if there is 'still' no network activity,
disconnect.
Thank you.
Serene |
|
| Back to top |
|
 |
nelz Moderator

Joined: Mon Apr 04, 2005 12:52 pm Posts: 8036 Location: Warrington, UK
|
Posted: Wed Mar 27, 2013 4:20 pm Post subject: |
|
|
Something like this?
| Code: | if iptstate -1 -t | grep -qv "Total States: 0"; then
rm -f /tmp/no-network-activity
exit
fi
if [[ -f /tmp/no-network-activity ]]; then
nmcli nm enable false
rm -f /tmp/no-network-activity
else
touch /tmp/no-network-activity
fi |
_________________ "Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein) |
|
| Back to top |
|
 |
serene LXF regular

Joined: Sun Jun 19, 2005 1:43 pm Posts: 101
|
Posted: Wed Mar 27, 2013 5:49 pm Post subject: |
|
|
Thank you so much Nelz.
Mine didn't look anything like that.
Beau-ti-fulllllllll. Much appreciated.
Odd how there isn't a feature in gnome or network-manager
to acomplish this.
Best regards,
Serene.
[SOLVED] |
|
| Back to top |
|
 |
nelz Moderator

Joined: Mon Apr 04, 2005 12:52 pm Posts: 8036 Location: Warrington, UK
|
Posted: Wed Mar 27, 2013 6:10 pm Post subject: |
|
|
| serene wrote: | | Odd how there isn't a feature in gnome or network-manager to acomplish this. |
Maybe because no one has asked for it? I can't think of a need for it myself. _________________ "Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein) |
|
| Back to top |
|
 |
| View previous topic :: View next topic |
|