Skip to contentSkip to conversation

How to wait for kernel messages?

DISCUSSION Jim Keniston 2 participants 2 messages Oct 14, 2003

lore
Share & tools
lore
#0 lore raw
Quoted 9 lines · Sebastian Piecha

I have some problems with one NIC. Due to lack of time as an workaround I'd like to wait for the kernel message "NETDEV WATCHDOG:
eth0: transmit timed out" and ifconfig down/up the NIC.

How can I trigger any action by such a kernel message? Do I have to grep the kernel log?

Mit freundlichen Gruessen/Best regards,
Sebastian Piecha

If you had LTC's Event Logging installed, and you had your kernel configured to forward printk messages to the event log, you could do something like this:

evlnotify -f 'data~"NETDEV WATCHDOG: eth0: transmit timed out"' \
-a 'ifconfig eth0 down; ifconfig eth0 up'

That would cause the ifconfig down/up to run each time the indicated printk happened.

Jim Keniston
IBM Linux Technology Center

#1 lore raw
Quoted 9 lines · Sebastian Piecha
Quoted 8 lines

I have some problems with one NIC. Due to lack of time as an workaround I'd like to wait for the kernel message "NETDEV WATCHDOG:
eth0: transmit timed out" and ifconfig down/up the NIC.

How can I trigger any action by such a kernel message? Do I have to grep the kernel log?

Thanks a lot for all the hints. I'm using now a fifo to which syslogd is logging kernel messages. A shell script greps the right message.

I attach the shell script inline for whom it may be interesting.

Mit freundlichen Gruessen/Best regards,
Sebastian Piecha

EMail: [email protected]

The following section of this message contains a file attachment prepared for transmission using the Internet MIME message format. If you are using Pegasus Mail, or any other MIME-compliant system, you should be able to save it or view it from within your mailer. If you cannot, please ask your system administrator for assistance.

---- File information -----------

     File:  check_nic.txt
     Date:  15 Oct 2003, 0:56
     Size:  771 bytes.
     Type:  Text

#!/bin/bash

# Signalling
trap 'exit 0' SIGTERM
trap '' SIGHUP

# grep
arg1="NETDEV WATCHDOG: eth0: transmit timed out"
#arg2="dhcpd: receive_packet failed on eth0: Network is down"

# Syslog
tag=$0
prio="kern.err"

fifo=/var/log/check_nic

IFCONFIG=$(which ifconfig)
SLEEP=$(which sleep)
EGREP=$(which egrep)
DATE=$(which date)
HOSTNAME=$(which hostname)
LOGGER=$(which logger)

while true
do
read line < $fifo
echo $line | \
$EGREP -e "$arg1" \
> /dev/null 2>&1
if [ $? -eq 0 ] ; then
$IFCONFIG eth0 down
$SLEEP 1
$IFCONFIG eth0 up
$LOGGER -t $tag -p $prio "eth0 down, restarting..." $SLEEP 5
fi
done