Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Auto disconnect network after 20 minutes of inactivity

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help!
View previous topic :: View next topic  
Author Message
serene
LXF regular


Joined: Sun Jun 19, 2005 1:43 pm
Posts: 111

PostPosted: Tue Mar 26, 2013 12:50 pm    Post subject: Auto disconnect network after 20 minutes of inactivity Reply with quote

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
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8365
Location: Warrington, UK

PostPosted: Tue Mar 26, 2013 2:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
serene
LXF regular


Joined: Sun Jun 19, 2005 1:43 pm
Posts: 111

PostPosted: Wed Mar 27, 2013 12:07 pm    Post subject: Reply with quote

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
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8365
Location: Warrington, UK

PostPosted: Wed Mar 27, 2013 4:20 pm    Post subject: Reply with quote

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
View user's profile Send private message
serene
LXF regular


Joined: Sun Jun 19, 2005 1:43 pm
Posts: 111

PostPosted: Wed Mar 27, 2013 5:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8365
Location: Warrington, UK

PostPosted: Wed Mar 27, 2013 6:10 pm    Post subject: Reply with quote

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 user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help! All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast