0

Good morning,

I have a home server running Ubuntu 14.04.3 LTS. It's a desktop connected to my wi-fi connection via an USB adaptor. The issue here is that randomly it gets disconnected from the network and asks again for the password (which is always the same and correctly stored, in fact it's already typed in the dialog that pops up) and I have to manually click or press enter to connect it again.

I have added to my crontab this small script

#!/bin/bash

if ! [ "$(ping -c 1 google.com)" ]; then
    service network-manager restart
fi

it runs every 5 minutes

*/5 * * * * /home/***/keepalive.sh

but it does not seem to help and i often find my server disconnected. What am I doing wrong?

muru
  • 197,895
  • 55
  • 485
  • 740
Seb
  • 209
  • 3
  • 10

1 Answers1

1

Replace service with the full path to service binary i.e. /usr/sbin/service:

#!/bin/bash
if ! [ "$(ping -c 1 google.com)" ]; then
    /usr/sbin/service network-manager restart
fi

Also put this in root's crontab as restarting network-manager requires root privilege, alternately you can grant yourself password-less sudo access for this command only, then you can use sudo /usr/sbin/service network-manager restart.

heemayl
  • 91,753