2

Im running linux and I have a task which runs only after midnight. The internet connection I use for this, goes offline if there's a period of inactivity and I want to keep the internet connection alive until midnight by some means (ex: putting it to some MINIMAL use so as to keep connection "active").

What is the best method to accomplish this task ?

2 Answers2

2

the easiest way I can think of would be to add a cron job which pings a dns server by adding a line like this one to /etc/crontab :

#
#┌───────────── minute (0 - 59)
#│ ┌───────────── hour (0 - 23)
#│ │    ┌───────────── day of month (1 - 31)
#│ │    │ ┌───────────── month (1 - 12)
#│ │    │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday;
#│ │    │ │ │                                       7 is also Sunday)
#│ │    │ │ │
#│ │    │ │ │
#* *    * * *

 * *    * * *   user    ping -c 3 8.8.8.8 &> /dev/null

This command would ping Google's DNS server 8.8.8.8 3 times every minute.

"user" should be replaced with any of your system users. /dev/null is there to mute the output of the command and prevent it to go in /var/log/syslog

You need to understand though how frequently you are required to ping the server in order to keep your connection alive. Hopefully you don't need to do it every minute.

If the frequency should be in the order of seconds then you need to write a customized script and run it from crontab instead of the "ping" command.

It would be also better to ping a server of yours living outside your network (if you have one) instead of Google's DNS.

1

The best option is obviously to reconfigure your router/modem so that it won't take your internet connection offline during the hours you need it to be online.

HBruijn
  • 84,206
  • 24
  • 145
  • 224