Bug 238120 - cron(8) doesn't set the HOME environment variable to users's home directory when command runs under regular user
Summary: cron(8) doesn't set the HOME environment variable to users's home directory w...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 12.0-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-25 19:28 UTC by Yuri Victorovich
Modified: 2019-06-21 12:48 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer freebsd_triage 2019-05-25 19:28:03 UTC
When crontab contains
> 10     *       *       *       *         yuri     env DISPLAY=:0.0 /usr/local/bin/bash /path/to/some/script

this script is run by cron(8) with HOME=/var/log

Once the field "who" in crontab is set to some user, cron(8) should also set the "HOME" environment variable properly.

HOME=/var/log looks wrong in any case.

(Not sure if "root" also suffers from this problem.)


FreeBSD nohost 12.0-STABLE FreeBSD 12.0-STABLE r347548 GENERIC  amd64
Comment 1 WHR 2019-06-21 08:55:19 UTC
Can't reproduce on 12.0-STABLE r349024 GENERIC amd64.
Comment 2 Yuri Victorovich freebsd_committer freebsd_triage 2019-06-21 09:21:00 UTC
On 12.0-STABLE r347548 GENERIC  amd64

Add this line to /etc/crontab:
> *     *       *       *       *         yuri     /home/yuri/cron-env-test.sh


/home/yuri/cron-env-test.sh contains:
> #!/bin/sh
> echo "`date`: "$HOME >> /tmp/cron-env-test.txt

It printed into /tmp/cron-env-test.txt:
> Fri Jun 21 02:18:00 PDT 2019: /var/log
Comment 3 Bob Bishop 2019-06-21 10:16:57 UTC
This bug refers to /etc/crontab. crontab(5) says "HOME [is] set from the /etc/passwd line of the crontab's owner", true for user crontabs but apparently not for /etc/crontab.

This looks like a documentation problem. crontab(5) doesn't really describe /etc/crontab, cron(8) notwithstanding.
Comment 4 WHR 2019-06-21 12:48:01 UTC
(In reply to Yuri Victorovich from comment #2)

The line I added in /etc/crontab is:

*	*	*	*	*	WHR	/home/WHR/cron-env-test.sh

cron-env-test.sh file is exactly same.

The result is:

[WHR@x ~]$ cat /tmp/cron-env-test 
Fri Jun 21 20:41:00 CST 2019: /usr/home/WHR
Fri Jun 21 20:42:00 CST 2019: /usr/home/WHR
Fri Jun 21 20:43:00 CST 2019: /usr/home/WHR
Fri Jun 21 20:44:00 CST 2019: /usr/home/WHR
Fri Jun 21 20:45:00 CST 2019: /usr/home/WHR
Fri Jun 21 20:46:00 CST 2019: /usr/home/WHR
[WHR@x ~]$ uname -a
FreeBSD x 12.0-STABLE FreeBSD 12.0-STABLE r349024 GENERIC  amd64