[H-GEN] crontab question

Benjamin Carlyle benjamincarlyle at optusnet.com.au
Wed Dec 15 08:30:09 EST 2004


> Anthony Irwin wrote:
> > I have set up a simple script to check if the Internet is running and 
> > connect to the Internet if it is not. The problem is if I run the script 
> > from a cron job it doesn't work, running it from the shell however works 
> > as I would expect
> > Below is the line in the root crontab
> > 0,30 * * * * /root/scripts/checkpppstatus.sh
> > Below is the script
> > #!/bin/bash
> > /sbin/ifconfig|/bin/grep ppp0 || /usr/bin/pon

I deleted the original email on this subject, thinking the cron issue
would be answered fairly quickly in subsequent emails. Since it wasn't I
thought I'd put a few cents into the ring. Sorry if this upsets
someone's threaded mailer :)

My theory: Different environments.

When you run a script (or scripts) from the command-line you are using
your standard environment. This comes from your .profile and from other
sources. When you run a program from cron, it is probably missing one or
more of these things (it may just be inheriting the environment from
cron itself). I would suspect given the simplicity of other parts of the
expression that the pon script (is it still a script these days?) is a
likely candidate for these problems. Looking at the mail cron sends you
after it fails will probably give you a clue on what is going wrong, for
example it may indicate that it can't find a certain program due to a
truncated PATH variable. Alternatively, ifconfig may have different
output to that which you expect when run from cron under these
conditions.

If your problem hasn't been solved by other means I would focus on those
emails to indicate what went wrong. If you can't see anything from
there, try pulling the command-line apart by placing the ifconfig,
ifconfig and grep, and the pon separately into cron and ensuring they
all work individually. Check the email output from each of these to
diagnose possible issues.

-- 
Benjamin Carlyle <benjamincarlyle at optusnet.com.au>





More information about the General mailing list