Matt Garman wrote:
> I took the smarts of your script, and also wrote a simple logging
> tool. It's just a wrapper for the syslog(3) function call (that
> allows you to log to syslog via the shell).
>
> In root's crontab, I have this entry:
>
> * * * * * /usr/local/sbin/chkpppoe.sh
>
> The chkpppoe.sh script looks like this:
>
> #!/bin/sh
>
> PATH=/sbin:/bin:/usr/sbin:/usr/bin
> SYSLOGGER=/usr/local/sbin/syslogger
> IFACE=pppoe0
> PROGNAME=chkpppoe.sh
>
> VAR=`ifconfig ${IFACE} | grep "inet " | cut -c 7`
>
> if [ $VAR = "0" ];
> then
> ${SYSLOGGER} "${PROGNAME}: ${IFACE} appears to be down;
attempting
> to bring it back up" ifconfig ${IFACE} up
> sleep 60
> else
> ${SYSLOGGER} "${PROGNAME}: ${IFACE} appears to be up; doing
nothing"
> fi
>
> #end of chkpppoe.sh
>
> The 'syslogger' program is this trivial program:
>
>
> /* syslogger.c begin */
> #include <syslog.h>
> #include <stdarg.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
>
...
>
> I just saw the program actually work, and can verify it in
> /var/log/messages:
>
> ...
> Aug 23 09:14:01 excrement syslogger: chkpppoe.sh: pppoe0 appears to
> be up; doing nothing
> Aug 23 09:14:08 excrement /bsd: pppoe0: down
> Aug 23 09:14:08 excrement /bsd: pppoe0: phase terminate
> Aug 23 09:14:16 excrement /bsd: pppoe0: phase dead
> Aug 23 09:15:01 excrement syslogger: chkpppoe.sh: pppoe0 appears to
> be down; attempting to bring it back up Aug 23 09:15:01 excrement
> /bsd: pppoe0: phase establish
> Aug 23 09:15:01 excrement /bsd: pppoe0: phase authenticate
> Aug 23 09:15:03 excrement /bsd: pppoe0: phase network
> Aug 23 09:16:01 excrement syslogger: chkpppoe.sh: pppoe0 appears to
> be up; doing nothing ...
>
>
> Hopefully someone finds this useful :)
Since the fixes for this are not in stable and I should probably be
running -current instead of this workaround, logger does the job just
fine...
$ cat pppoecheck
#!/bin/sh
#
# NAME
# pppoecheck - attempt to restart pppoe interface if it is down
# pppoe0 interface exists
if [ -f /etc/hostname.pppoe0 ]; then
down=`ifconfig pppoe inet | fgrep 0.0.0.0`
if [ "$down" ]; then
logger -p user.err pppoe0: phase restart
ifconfig pppoe0 up
fi
fi