Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 May 1998 05:24:20 -0400 (EDT)
From:      CyberPeasant <djv@lucy.bedford.net>
To:        dwhite@resnet.uoregon.edu
Cc:        djv@bedford.net, freebsd-questions@FreeBSD.ORG
Subject:   Re: /etc/crontab fishiness
Message-ID:  <199805240924.FAA04524@lucy.bedford.net>
In-Reply-To: <Pine.BSF.3.96.980524004330.9142z-100000@gdi.uoregon.edu> from Doug White at "May 24, 98 00:44:08 am"

next in thread | previous in thread | raw e-mail | index | archive | help
Doug White wrote
> On Fri, 22 May 1998, CyberPeasant wrote:
> 
> > The crontab(5) man page asserts that variables declared in a crontab,
> > such as
> > 
> > HOME=/var/log
> > 
> > in /etc/crontab will be passed to the commands executed. In the case
> > at least of /etc/crontab executing the supplied /etc/weekly script,
> > this is not the case.
> > 
> > Place "echo $HOME" in that script, and see "/root", not the expected
> > "/var/log".
> 
> This is probably because the user's shell resets $HOME.  Remember that the
> task is run as the user.
> 
> Doug White                              | University of Oregon  
> Internet:  dwhite@resnet.uoregon.edu    | Residence Networking Assistant
> http://gladstone.uoregon.edu/~dwhite    | Computer Science Major

Doug, that is correct, thanks for pointing it out! In my case, root
uses bash as default shell. (Note, this bash is not linked to sh.)
The distributed .profile (also good for a root using /bin/sh), does
in fact reset HOME. The distributed csh startup files for root do
not do this, which explains why this complaint is not universal.

I define HOME for root as a security measure anyway (probably a
lame one, but I prefer to override umask, PATH and HOME in root's
startups).  Whoever wrote the default .profile for root seems to
agree, (jkh?) (probably where I got the idea, anyway, long ago on
another BSD version).

A possible fix is to add the -p switch (suppressing sourcing of
.profile) to the SHELL declaration in /etc/crontab.

y.a. fix is the one I suggested originally, setting HOME in /etc/weekly.

y.a. fix is to place some new code in /root/.profile to examine
the incoming HOME from login, check it against a list of "OK" homes,
(possibly /:/var/log:/root) and change it to /root if it is not
in that list.

Probably the simplest thing would be to add a comment at the
head of /etc/weekly, advising of the problem. It's pesky to
track down, and I see it occuring regularly enough to be a FAQ.

Puzzle: man 5 crontab says in the EXAMPLE section:
     # use /bin/sh to run commands, no matter what /etc/passwd says
     SHELL=/bin/sh
	   
Why, if the default .profile sets root's HOME to /root, do csh
using roots (whose csh is not actually invoked) /not/ see this problem?

Dave
-- 
         --== Things that suck: PA vehicle inspections ==--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199805240924.FAA04524>