Click to See Complete Forum and Search --> : Simple Cron question


Ricky Leonhart
05-10-2001, 03:20 AM
Hi all,

I am using a linux as my firewall and NAT gateway to share the cable modem service for my home network. I wrote I very simple bash script to keep check the existance of ip address of the external NIC because the ip often disappear due to dhcp lease time expire or traffic idle time period. Part of the script is like this:

#!/usr/bash
ifconfig eth1 | grep inet
.
.
.

I setup the crontab to run this script every minute, but I run into a problem of cron generate a mail to the root account every time it run. So it's just kinda like mail spamming. Is there any way to solve this problem? I checked the manual page of cron but it doesn't mention about how to turn off this function.

Best Regards,
Jacky Liu

"Genius or Wacko? Majority or Minority… "

EscapeCharacter
05-10-2001, 04:02 AM
you could get the current ip then check to see if it is different every minute and if it is then the script will sendmail the new ip

something like
CURIP = 127.0.0.1
OLDIP = ifconfig whatever
then just
if [ $CURIP != OLDIP ] then;
sendmail;
echo $CURIP > fileyoucheck
else
do nothing

^
|
|
very bad code but its just a rough :)

[ 10 May 2001: Message edited by: EscapeCharacter ]

tnordloh
05-10-2001, 04:25 AM
By default, cron sends any error or output to the email of the user who created the crontab entry. You just have to redirect those messages.

For example, let's say my script listed my home directory like this;

ls -l

Obviously, that line entered in a crontab entry, like this

5 * * * * ls -l

would nicely fill my email with directory listings.

As you've probably guessed by now, I could redirect with a command similar to

5 * * * * ls -l >/dev/null 2>/dev/null

in order to redirect all data generated, as well as all errors diretly to the trash. Good luck with your script, hope this helps.

Ricky Leonhart
05-10-2001, 11:17 PM
Thanks all,

I appiled tnordloh's method and seem it works for me.. thanks alot. Also, thanks for EscapeCharacter's suggestion as well.

Best Regards,
Jacky Liu

"Genius or Wacko? Majority or Minority… "

Energon
05-11-2001, 01:14 AM
ummm... how come I never get any output from cron? I have it run some scripts in the background (using &), is that why I never get any mail from cron about it?

Bradmont2
05-11-2001, 02:32 AM
I wrote a script to check my IP addy every hour and email it to a web-based account if it changed... I just saved the old IP in a file in /etc, and compared it with the new one every time the script was run. A nice easy way to send the email is like this:


mail root < somefile.txt


you can, of course, replace 'root' with any valid email address. :)

<edit> PS. Don't you think every minute is a bit excessive? :) </edit>

[ 11 May 2001: Message edited by: Bradmont ]

tnordloh
05-11-2001, 06:15 AM
Energon, I'm not sure. Is it possible that these background scripts don't generate any output? Just guessing...

[ 11 May 2001: Message edited by: tnordloh ]