1

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 Answers 2

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.

1
  • I had overlooked this option before I posted the question so had to choose this as the best answer. My "router" is a ZTE MF 10 that uses a 3G dongle to make an internet connection. There's an option called "on demand connection" with an idle timeout, which seemed to work well for my purpose - going online when needed and disconnecting when not. Previously I had chosen the "auto connect" option which means to connect automatically as soon as router was powered on and disconnect if there's inactivity and never to connect unless router was power cycled. Apr 11, 2017 at 3:22
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .