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

2007-08-31 Thread Hinkie
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" <[EMAIL PROTECTED]>
To: "Hinkie" <[EMAIL PROTECTED]>
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 

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


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

2007-08-31 Thread Hinkie
Dear People

As a courtesy to anyone interested I have finally sovled this (I hope), this is 
what I did, this is on a FreeBSD pfSense firewall router.

Essentially the fix is to ping the static IP's first hop, if this is down then 
flick the WAN NIC state down and up, this restores 
the lost connection where the Motorola 5101 has stopped sending packets 
(presumably for some incompatibility reason)  The Motorola 
5101 has today been replaced with a 5100, the ISP tell me most commercial lines 
are running the 5100 as they say it is more router 
compatible than the newer 5101.  I'll advise if the 5100 exhibits the same 
behaviour(!) however if it does the following should 
address it within a minute.  If you are copying it be sure to copy it exactly 
as spaces in the wrong place stuff it upetc!!

For both the lists and my record it is done by:

=> in /etc/crontab add
*/1 * * * * root /usr/bin/pinger.sh

=> 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

=> from exec.php run chmod u+x /usr/bin/pinger.sh

=> from exec.php run ls -l /usr/bin/pinger.sh
and check there is an x in the file permissions (for executable)

It will have run when you see a log series of commands starting with
Sep 1 11:32:13 kernel: em0: link state changed to UP
Sep 1 11:32:11 kernel: em0: link state changed to DOWN

The only problem I see with this approach is that whenever the Internet is down 
for whatever reason the WAN interface is going to be 
disconnected and reconnected every minute, as well as filling the logs with 
this info, but that seems only of concern from the 
perspective of filling the log with rubbish.  I might tinker with it to send me 
an email to advise me when the code has also run .

Thank you again to the people who worked with me on this.

Kind regards
David Hingston 
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


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

2007-08-29 Thread Hinkie
Eric

You are of course correct, it runs under "sh"

I think that means I have to run it in a separate script file

I write it as (First_Hop subs with a.b.c.1)

#!/bin/sh
if ! ping -c1 First_Hop >/dev/null 2>/dev/null
   then 
echo First_Hop_OK
   else
ifconfig em0 down && ifconfig em0 up
echo Restored
fi

Save as /etc/pinger.sh

Try run:

pfsense-p266ii:~#  /etc/pinger.sh
/etc/pinger.sh: Permission denied.

Try fix:

pfsense-p266ii:~#  chmod 777 /etc/pinger.sh
chmod: /etc/pinger.sh: Read-only file system

H  I assume if it won't run here then crontab won't run it either?

Kind regards 
David Hingston

- Original Message - 
From: "Eric Crist" <[EMAIL PROTECTED]>
To: "Hinkie" <[EMAIL PROTECTED]>
Cc: 
Sent: Thursday, August 30, 2007 7:30 AM
Subject: Re: FreeBSD Cron Job to run (ifconfig em0 down; ifconfig em0 up)


David,

The script I provided assumes the sh shell.  Most shell scripts have  
been historically written for the bourne shell.  Before running the  
script I sent you, try typing sh at the command line.  Then,  
run the line I sent your way.

Let me know how it works for you!

Eric


On Aug 29, 2007, at 2:16 PMAug 29, 2007, Hinkie wrote:

> Hi Eric
>
> Thank you for that, I think I see one thing I was doing wrong  
> (putting the ping into the if!)
>
> Running your code in the command window I get (Following the  
> successful ping)
>
> TESTV=0: Command not found.
> TESTV: Undefined variable.
>
> As you can tell I am learning this syntax!
>
> Can you help me further?
>
> With thanks
>
> David Hingston
>
> - Original Message -
> From: "Eric Crist" <[EMAIL PROTECTED]>
> To: "Hinkie" <[EMAIL PROTECTED]>
> Cc: 
> Sent: Thursday, August 30, 2007 2:17 AM
> Subject: Re: FreeBSD Cron Job to run (ifconfig em0 down; ifconfig  
> em0 up)
>
>
> On Aug 29, 2007, at 8:03 AMAug 29, 2007, Hinkie wrote:
>
>> 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?
>
> Here's what I'd use:
>
> ping -c 1 a.b.c.d; TESTV=$?; if [ $TESTV != 0 ]; then `ifconfig em0
> down`; fi
>
> HTH
> -
> Eric F Crist
> Secure Computing Networks
>
> ___
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions- 
> [EMAIL PROTECTED]"

-
Eric F Crist
Secure Computing Networks

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


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

2007-08-29 Thread Hinkie
Hi Eric

Thank you for that, I think I see one thing I was doing wrong (putting the ping 
into the if!)

Running your code in the command window I get (Following the successful ping)

TESTV=0: Command not found.
TESTV: Undefined variable.

As you can tell I am learning this syntax!

Can you help me further?

With thanks

David Hingston

- Original Message - 
From: "Eric Crist" <[EMAIL PROTECTED]>
To: "Hinkie" <[EMAIL PROTECTED]>
Cc: 
Sent: Thursday, August 30, 2007 2:17 AM
Subject: Re: FreeBSD Cron Job to run (ifconfig em0 down; ifconfig em0 up)


On Aug 29, 2007, at 8:03 AMAug 29, 2007, Hinkie wrote:

> 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?

Here's what I'd use:

ping -c 1 a.b.c.d; TESTV=$?; if [ $TESTV != 0 ]; then `ifconfig em0  
down`; fi

HTH
-
Eric F Crist
Secure Computing Networks

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


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

2007-08-29 Thread Hinkie
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 

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"