Date: Wed, 29 Aug 2007 08:42:34 -0500 From: Reid Linnemann <lreid@cs.okstate.edu> To: Hinkie <Hinkie@paradise.net.nz> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: FreeBSD Cron Job to run (ifconfig em0 down; ifconfig em0 up) Message-ID: <46D577CA.4030008@cs.okstate.edu> In-Reply-To: <01a901c7ea3d$0ad62720$1e00a8c0@cheqsoft.local> References: <01a901c7ea3d$0ad62720$1e00a8c0@cheqsoft.local>
next in thread | previous in thread | raw e-mail | index | archive | help
Written by Hinkie on 08/29/07 08:03>>
> Hi
>
> I want to run a cron job in /etc/crontab that runs (ifconfig em0 down; ifconfig em0 up) if my cables static ip gateway can't be pinged but I can't figure it out. I can't get the syntax that runs in the command window, to then put intot the crontab....
>
> Can anyone help me?
>
> I've tried all sorts such as:
>
> if (ping -c1 a.b.c.1 != 1) then ifconfig em0 down; ifconfig em0 up endif
>
> if ping -c1 a.b.c.1 != 1 then ping -c1 203.97.234.1 endif
>
> if ping -c1 a.b.c.1 (ifconfig em0 down; ifconfig em0 up)
>
> if ( ping -c1 a.b.c.1 != 1) ( ping -c1 203.97.234.182 )
>
> if $command("=ping -c1 a.b.c.1 =0") echo sucess
>
> if ping -c 1 -w 1 a.b.c.1 >/dev/null echo sucess
>
> if [[ (ping -q -c 3 a.b.c.1) == @(*100% packet loss*) ]]; echo sucess
>
> if ! ping -c a.b.c.1 > /dev/null ; then echo sucess ; echo fail; fi
>
> Any help would be appreciated.
>
> Kind regards
> David Hingston
>
I would recommend you make a shell script, place it in /root/bin or
something else sensible, and have cron call that. I think it's generally
frowned upon to have excessive scripting directly in the crontab. The
following script should do what you want:
#!/bin/sh
if ! ping -c1 203.97.234.1821>/dev/null 2>/dev/null
then ifconfig em0 down && ifconfig em0 up
fi
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?46D577CA.4030008>
