4

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.

2 Answers2

1

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.

robru
  • 674
0

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.