Need assistance with shell script / monitor network link down.

Installing, Configuring, Troubleshooting server daemons such as Web and Mail
Post Reply
SupermanInNY
Posts: 69
Joined: 2006/01/14 16:04:37

Need assistance with shell script / monitor network link dow

Post by SupermanInNY » 2008/05/25 01:41:42

Hi All,

I have a linux CentOS 4.6 with the following kernel: 2.6.9-67.0.4.
I'm using bash

/root # set
BASH=/bin/bash

My server is connected to a Dell 2724 PowerConnect Switch and I'm suspecting either there is a problem with the server or the switch.
I can't tell a whole lot about either one, meaning I don't know who is originating the problem.

My problem is that every so often, on a random basis, I get the following message:

less /var/log/messages

May 25 04:06:44 server kernel: eth0: link down

Nothing that I'm doing or that I'm aware of that is causing the link to get down.
Thankfully, I have a KVMoverIP and I'm able to connect to the server remotely and run:

service network restart

It kicks the link back up and everything is then working great.

So where do I need your assistance?


I want a shell script that will run in a screen and will monitor /var/log/messages .
If it encounters the link down on the Last Line of the file, it should run the "service network restart".

It can do the check every minute. That will be plenty.

This problem happens about once a day with no apparent or early warnings.
Nor are there any other messages that alerts me that such a problem exists.

Any pointers on how to run a monitor script ( grep "link down" | tail -f /var/log/messages )? and then kick the "service network restart ?

Thanks, for any pointers.

-Sup.

yyagol
Posts: 1015
Joined: 2006/06/10 18:27:44
Location: 32 4′N 34 47′E
Contact:

Re: Need assistance with shell script / monitor network link down.

Post by yyagol » 2008/05/26 05:22:38

do it with mii-tool not with the log ,

[code] mii-tool eth0 |grep "link ok" 1>/dev/null || service network restart [/code]

put this script in crontab ( crontab -e ) to run every minute and you are done.
btw it sounds like you do have a problem with the ethernet card , if you got another
NIC on that machine , consider using it instead .

SupermanInNY
Posts: 69
Joined: 2006/01/14 16:04:37

Re: Need assistance with shell script / monitor network link down.

Post by SupermanInNY » 2008/05/26 23:13:13

[quote]
yyagol wrote:
do it with mii-tool not with the log ,

[code] mii-tool eth0 |grep "link ok" 1>/dev/null || service network restart [/code]

put this script in crontab ( crontab -e ) to run every minute and you are done.
btw it sounds like you do have a problem with the ethernet card , if you got another
NIC on that machine , consider using it instead .[/quote]

Hi,

Thanks for the script.
Manually, the script runs fine.
However when I try to let the cron work it fails.

I've tried to identify what the problem is:

[code]

vi /etc/networkproblem.sh
[/code]
and placed:

[code]

mii-tool eth0 |grep "link ok" 1>/dev/null || service network restart
wall hey it worked

in it.

chmod 755 /etc/networkproblem.sh

crontab -e
* * * * * root /etc/networkproblem.sh

[/code]

Every minute I get the broadcast message:

hey it worked

But the script does't get the network started.

If I do:

mii-tool I get the error:

[code]
SIOCGMIIPHY on 'eth0' failed: Invalid argument
no MII interfaces found

[/code]

If I run it manually:

[code]
. /etc/networkproblem.sh
[/code]

it shows:

[code]

/etc # ./networkproblem.sh
SIOCGMIIPHY on 'eth0' failed: Invalid argument
Shutting down loopback interface: [ OK ]
Setting network parameters: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]

Broadcast message from root (pts/0) (Tue May 27 02:08:22 2008):

hey it worked

[/code]

So, I'm confused on how to 'force' it to run.

I appreciate your assistance with this.
As for the NIC,. this is an old server, P4 with 1GB RAM and an EliteGroup motherboard.
I plan to replace it in the future, but aside from this random weired behavior, everything else works great.

So going back to understanding the reason it is not working: any pointer why the script fails on running the mii-tool portion?
The broadcast msg is working fine.

thanks,

-Sup.

yyagol
Posts: 1015
Joined: 2006/06/10 18:27:44
Location: 32 4′N 34 47′E
Contact:

Re: Need assistance with shell script / monitor network link down.

Post by yyagol » 2008/06/26 10:09:09

put PATH on crontab -e

[code]PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
*/5 * * * * /root/blabla.sh[/code]

Post Reply

Return to “CentOS 4 - Server Support”