A script to restart the network-manager

Asked by Ian Ace

I'm currently running Karmic on my laptop and I want to do something to this wireless connectivity (connection drops) problem that's bugging me everytime I leave my laptop turned on for the whole night.

I want a script which I can place on my cron so if it detects (like pinging google.com every 20 minutes) that there is no Internet connectivity it will tend to restart the network-manager and have it reconnected again without me interfering.

*The only solution I could do is to restart the laptop so I can be connected again, Logging out does not solve the problem either*

TIA.

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Arnaudus (a-lerouzic) said :
#1

Hi,

First, you may want to try to restart the network manager by hand, to check if it fixes your problem: open a terminal and type

sudo NetworkManager stop

sudo NetworkManager start

and check if your network connection is repaired. If yes, you can probably put these commands into a script you launch every 20 minutes.

Revision history for this message
Ian Ace (iaculallad) said :
#2

Actually, the command "restart network-manager" works well for me as shown on the script I use below:

#!/bin/bash

if eval "ping -c 2 -w 3 google.com"; then
exit
else
restart network-manager
fi
exit

But problem comes when I am prompted with the password screen when i'm disconnected to the Internet. This password window interferes with the command so I need to close this window first and manually running the script above and I get connected.

I'll try to get the window's process name with ps when it re-appears so I can add a kill command for it on the script.

Can you help with this problem?

Provide an answer of your own, or ask Ian Ace for more information if necessary.

To post a message you must log in.