problems with init.d script via cron

Jason Joines joines
Wed Aug 25 11:04:30 PDT 2004


Jason Joines wrote:

> Bill Campbell wrote:
>
>> On Mon, Aug 23, 2004, Jason Joines wrote:
>>  
>>
>>>     I have an init.d script that works fine interactively.  That is 
>>> I     can use it to start, stop, restart, etc., the service via 
>>>     "/etc/init.d/scriptname arguments" from a command prompt.  
>>> However,     it fails when run from cron.
>>>
>>>     It has these variables and start line:
>>> CONFIGDIR=/etc/rembo
>>> CONFIGFILE=rembo.conf
>>> BINDIR=/opt/rembo
>>> BINFILE=rembo
>>> startproc $BINDIR/$BINFILE -v 4 -c $CONFIGDIR/$CONFIGFILE
>>>
>>>     I need to have cron restart this service nightly after some 
>>> files     are updated.  When I try to have cron do it the start line 
>>> generates     this error:
>>> cannot stat `/etc/rembo/.conf': No such file or directory
>>>
>>>     Looks like it's dropping the part between the front slash and 
>>> the     period.  I've tried all sorts of quotations and such but no 
>>> luck so     far.  Any ideas how to make this behave?
>>>   
>>
>>
>> This type of problem is almost always due to missing environment 
>> variables
>> that are set in the shell, but not in the cron environment.
>>
>> You may be able to identify the problem by comparing the shell
>> environment with the cron environment.  At the shell prompt
>> enter ``env | sort > /tmp/env.shell'', then add a line at the
>> beginning of the cron script ``env | sort > /tmp/env.cron'', and
>> finally compare the /tmp/env.shell and /tmp/env.cron files to see
>> what's missing from /tmp/env.cron.
>>
>> Bill
>> -- 
>> INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
>> UUCP:               camco!bill  PO Box 820; 6641 E. Mercer Way
>> FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 
>> 236-1676
>> URL: http://www.celestial.com/
>>
>> ``Guns are no more responsible for killing people than the spoon is
>> responsible for making Rosie O'Donnell fat.''
>> _______________________________________________
>> Linux-users mailing list
>> Linux-users at linux-sxs.org
>> http://mail.linux-sxs.org/cgi-bin/mailman/listinfo/linux-users
>>  
>>
>
>    Thanks, that was a good idea.  env.cron was almost completely empty 
> as compared to env.shell.  Not sure exactly what all needs to be 
> present in the cron environment but adding ". /etc/profile" to the 
> beginning of my script fixed the problem and I can work backward from 
> there.
>
> Jason
> =================================
> _______________________________________________
> Linux-users mailing list
> Linux-users at linux-sxs.org
> http://mail.linux-sxs.org/cgi-bin/mailman/listinfo/linux-users


    Well I did work backward and got it taken care of but it was a lot 
of work for something stupid on my part.  I sourced a copy of 
/etc/profile at the beginning of my cron script and it worked.  Then I 
started commenting stuff out line by line and rerunning it until it got 
down to the only thing left was setting the variable HOST.  I had used 
$HOST to do some stuff at the beginning of my script and it not being 
set caused everything else to go crazy.  I changed it to $HOSTNAME and 
everything was fine.  If I had just paid more attention to the ouput in 
env.shell and env.cron as you suggested I could've saved a lot of work.

Jason
=================================


More information about the Linux-users mailing list