root user HOME is now / in cron jobs ?

giox069

Dabbler
Joined
Jun 1, 2012
Messages
28
I have some old cron scripts which ran fine under FreeNAS 11.1. After upgrading to 11.3 they all failed.
It seems that in cron jobs, the environment variable $HOME is now set to / for root, instead of the real root user home dir /root, as defined in /etc/passwd.

Is it a bug or a feature ? :)
 

SweetAndLow

Sweet'NASty
Joined
Nov 6, 2013
Messages
6,421
root:*:0:0:root:/root:/bin/csh

This is what I have in my /etc/passwd on 11.3-U1. Maybe something you changed switched the root home dir?


Code:
root@tubby:~ # echo $HOME
/root
 

giox069

Dabbler
Joined
Jun 1, 2012
Messages
28
Yes, taht's correct. I have the same values in /etc/passwd and in the interactive shell (ssh) environment.
But try to create a new script, and put
Code:
echo $HOME > /tmp/myoutput.txt

in the script.
Schedule the script as a cron job and wait its execution. It should put only / on myoutput.txt
 
Last edited:

Hazimil

Contributor
Joined
May 26, 2014
Messages
172

giox069

Dabbler
Joined
Jun 1, 2012
Messages
28
Yes exactly the same issue. It's not a script problem. It's that the $HOME variable changed, and is now different when your script is executed from the SSH shell (/root as reported in /etc/passwd) or the cron job (/ by default now).
With previous versions of FreeNAS, $HOME was correctly set to /root in both cases.

As a workaround you can add
Code:
export HOME=/root

to your script.

So what I'm asking to FreeNAS developers is:

The variable $HOME changed from /root to / in cronjobs processes in recent FreeNAS (11.3 or 11.2). This happens also when root's user home settings is /root.

Is it intentional or a bug?
 

Hazimil

Contributor
Joined
May 26, 2014
Messages
172
I suggest you log as a bug if you want a response /fix from IX, good luck!
 
Top