FreeBSD Cron Job to run (ifconfig em0 down; ifconfig em0 up)

Hinkie Hinkie at paradise.net.nz
Fri Aug 31 19:56:16 PDT 2007


Wow, thats Kewl!

Thanks Robert, yes, that makes the code a little more portable!

In a similar vein, to make it truly run, and for being so good(!), how do I automate getting the WAN interface name (em0 dc0 etc) on 
different machines!?

Kind regards
David Hingston


----- Original Message ----- 
From: "Robert Huff" <roberthuff at rcn.com>
To: "Hinkie" <Hinkie at paradise.net.nz>
Sent: Saturday, September 01, 2007 2:45 PM
Subject: Re: FreeBSD Cron Job to run (ifconfig em0 down; ifconfig em0 up)



Hello:

> from edit.php create / write into new file /usr/bin/pinger.sh
#!/bin/sh

ping -c1 Insert_1st_Gateway_Hop_Here_commonly_Static_IP_a.b.c.1
if [ $? -eq 2 ]; then
        ifconfig em0 down
        ifconfig em0 up
        echo 'Gateway Down'
else
        echo 'Gateway Up'
fi

And you might consider replacing:

ping -c1 Insert_1st_Gateway_Hop_Here_commonly_Static_IP_a.b.c.1

with:

ping -c1 `netstat -rn | head -n 5 | tail -n 1 | awk '{ print $2 }'`



Robert Huff 



More information about the freebsd-questions mailing list