Andrew Beresford's Blog

Archive for August, 2008

Cron’s environment is not your environment

without comments

Ok… a work related post.

I’ve been doing some work on systems that run commands automatically with Cron and our developers have been hitting some problems with commands that run fine as root, but don’t work correctly when they are executed by cron.

The cause of this is differences in the environment between the interactive root user environment and the cron root user environment. Let me demonstrate;

root@eeyore:~# env | wc -l
21

My interactive root user environment 21 lines of “stuff” in it, but if I run a env under cron and output that to a file I get this;

root@eeyore:~# wc -l /tmp/crontmp
5 /tmp/crontmp

Two quite different values.

The interactive $PATH is;

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bin:/usr/X11R6/bin

whilst the cron PATH is;

/usr/bin:/bin

Hence you will have difficulties finding tools outside of this rather limited path. Quite often things like Java are outside of the limited path.

If you want to have a more complete PATH, you’ll either have to define on the individual lines in your crontab, or at the top of the crontab entry.

Update

The limited crontab is defined in /etc/crontab. On a RHEL4 system it defines;


SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

Written by beezly

August 20th, 2008 at 3:32 pm

Posted in work

Tagged with

Back from Recording

with 2 comments

Yestterday I was at the wonderful Leeders Farm recording studio with the rest of the band I’m playing in. We had a great time, got two awesome songs recorded and I must say a big thanks to both Nick and Alex at Leeders Farm. I’ve just heard a quick mix of both songs we did and they sound fantastic.

Here’s a sneak preview video of us at the studio…

Written by beezly

August 12th, 2008 at 7:35 pm

Posted in Life,work

Tagged with , ,