0

I'm a Ubuntu 12.04 LTS user, and I want something that disconnect the Internet at a specific time. Here in this answer, there was an option in modem manager to disconnect the internet at specific time but unfortunately this has not worked for me.

Why I'm asking for such software

Sometimes I use night pack, my night pack time limit is 0000 hr - 0600 hr. So I start to download something e.g. a movie and then I go to sleep. One time it happened that I woke up at 0800 hr, the download was already over at 0430, but after 0600 some MB's were used, and cost of those extra MB's was more than my night pack! And so I need some helpful software.

Singh
  • 137
  • 10

3 Answers3

2

You could use cron to schechule a command.

To edit root's crontab:

sudo crontab -e

To shutdown your network interface (ie "eth0") every day at 5:55am. add this line:

55 05 * * * ifdown eth0

There is more information about it: cron howto

There is a graphical user interface (I haven't tried myself): gnome-schedule

J.Serra
  • 571
  • 1
  • 7
  • 25
1

Use cron to shedule a disconnect command at 6 in the morning. You can find information on how to use cron over at the community wiki.

You need to issue the command to shut down the network as root, so you want to use sudo crontab -e when adding the command as a cronjob.

You want to use either nmcli or ifdown as the command, depending on whether nmcli is installed on your system. You are on a really old version of ubuntu, which is why nmcli probably won't work, but i will include it here nevertheless.

  • With nmcli the command would be nmcli networking off.
  • With ifdown the command would be ifdown INTERFACE.

For the ifdown command you will have to find out which interface you want to shut down by looking at the output of sudo ifconfig. For your Ethernet Interface it will be something like eth0.

ApolloLV
  • 483
  • 2
  • 7
1

There's a variety of ways to do this. More preferred and automated way is to use cron.

My choice would be a neat scheduling program called at (not installed by default, you have to get it with sudo apt-get install at ). It allows scheduling commands to be executed at specific time. In your particular case, it would be used as such:

echo " nmcli networking off " | at 6:00

The good thing here is that nmcli doesn't require sudo. Downside is that you'd have to run it manually. To automate it, you can add that command as an autostart entry so that it schedules the command each time you log in. There's a variety of ways to do that as well - .desktop files, /etc/rc.local script,etc.

And there's a variety of commands that you can schedule - sudo service network-manager stop, sudo ifconfig wlan0 down , nmcli nm wifi off, etc.

Alternatively, you can schedule a computer shutdown at specific time with sudo shutdown -P 6:00.

Note: in my examples I am using wlan0 option, but if you substitute eth0 , that will operate on wired connection. Make sure to check man pages for nmcli and ifconfig and adapt everything to your networking needs accordingly.

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
  • Sir please tell what is the meaning of -P in sudo shutdown -P 6:00. It will help me to remember the command. – Singh Jul 26 '15 at 13:51
  • @Singh the -P flag means poweroff. This is specifically for shutting down computer. There is also -H or --halt flag (both are same), where system stops all processes, but machine is still powered on, then user can just press power-button to safely shutdown the system, but I personally use only -P. Read more in man shutdown – Sergiy Kolodyazhnyy Jul 26 '15 at 21:55