Is there any program or setting which can automatically disable a network connection after 5 minutes when it is enabled manually?
So that the user will have to enable the connection every 5 minutes manually, if they need it more than 5 minutes.
Is there any program or setting which can automatically disable a network connection after 5 minutes when it is enabled manually?
So that the user will have to enable the connection every 5 minutes manually, if they need it more than 5 minutes.
No need to ping google, you can check the status of the network directly with nmcli
.
Here's a script I whipped up for ya real quick:
#!/bin/bash
while :; do
if $(nmcli nm enable | grep -q enabled); then
echo 'Found connection! You got 5 minutes!'
sleep 300
nmcli nm enable false
else
echo 'No connection, checking again in 30s.'
sleep 30
fi
done
Just run this script at startup and it will stay running forever, constantly checking for an internet connection, and if it finds one it will disable it 5 minutes later.
nmcli
and it will tell you what commands you want to substitute. Should not be difficult at all, just make sure to change both the invocations of nmcli
in the script (the one that checks and the one that disables). They both have to point at the same connection or they'll get confused.
– robru
Mar 15 '14 at 05:35
Just to archive the answer:
#!/bin/bash
while :; do
if $(nmcli dev list iface eth0 | grep -q "not connected"); then
sleep 60
else
sleep 300
nmcli dev disconnect iface eth0
fi
done
where eth0
is the connection that is to be disconnected.
nmcli
to control NetworkManager. Wait for the connection to go up (you can ping google every 30 s or something like that), then wait five minutes, and then switch connection off. Look atman nmcli
for instructions. – Rmano Mar 11 '14 at 14:32