0

I have a problem with my Ubuntu machine. Every 15-20 mins my wifi stops working. The connection remains intact but internet access dies.

Whenever this happens - I restart Network-Manager and all is well for another 15 mins.

What I would like to do is set up a CRON job which does this for me. I have the following in my crontab...

*/2 * * * * service network-manager restart

(It is 2 mins for debugging)

This does not work though. I read online that when doing things akin to this via CRON, one needs to specify the full path (which I do not know).

Can anyone help me with this problem?

Sam
  • 101
  • 1
  • 3
  • 2
    Why not try doing things such as looking at the routing table and system logs in order to try to solve the actual problem instead of putting up with it like this? – Ignacio Vazquez-Abrams Jul 03 '13 at 21:40
  • Well the result of route -n doesn't seem to change. Will look for anything obvious in the logs. The machine runs headless and I just vnc into it from time to time on a separate connection. I don't use it for browsing as such. I just want to keep it online with minimum fuss. – Sam Jul 03 '13 at 22:47

3 Answers3

1

The asker has stated that they eventually added the necessary paths to the top of the crontab file. I thought it useful to direct others searching through this thread to a little more information about the solution.

See: Reasons why crontab does not work

Quote:

Cron passes a minimal set of environment variables to your jobs. To see the difference, add a dummy job like this:

          • env > /tmp/env.output

Wait for /tmp/env.output to be created, then remove the job again. Now compare the contents of /tmp/env.output with the output of env run in your regular terminal.

A common "gotcha" here is the PATH environment variable being different. Maybe your cron script uses the command somecommand found in /opt/someApp/bin, which you've added to PATH in /etc/environment? cron does not read that file, so runnning somecommand from your script will fail when run with cron, but work when run in a terminal.

...

You can also set the PATH variable in the crontab file, which will apply to all cron jobs. E.g.

> PATH=/opt/someApp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
> 
> 15 1 * * * backupscript --incremental /home /root
gslexie
  • 11
  • 1
0

You can start by looking in the log files (/var/log/*) to find which one(s) mention "your wifi", probably "wlan0". If not, use ifconfig -a to list your interfaces.

On my system, here's what looking for wlan0 looks like:

$ grep -li wlan0 /var/log/*
grep: /var/log/btmp: Permission denied
grep: /var/log/btmp.1: Permission denied
/var/log/dmesg.0
/var/log/kern.log
/var/log/kern.log.1
/var/log/pm-powersave.log
/var/log/pm-powersave.log.1
grep: /var/log/speech-dispatcher: Permission denied
/var/log/syslog
/var/log/syslog.1
/var/log/udev

Note that I ran the command as a non-root user, but btmp and speech-dispatcher logs aren't used by networking, so I don't really need to be root.

The next step would be to remove the "l" option from the grep, pipe the output through less, and find the interesting (from the timestamp or the contents of the message) lines.

grep -i wlan0 /var/log/* | less
waltinator
  • 36,399
0

In the end I just added the paths required to the top of the crontab and it all worked. Internet is unavailable for 30ish seconds once every 15 mins which is no biggy in my case.

Thanks for the input people.

Sam
  • 101
  • 1
  • 3