logoalt Hacker News

thaynetoday at 4:07 AM1 replyview on HN

I wouldn't say that the PATH is ambiguous, but cron does have some problems with PATH:

- the default value is missing some values you would expect, like /use/local/bin and /usr/sbin for root.

- on some distributions (for example Arch Linux) the man page doesn't even say what the default path is, or recommend setting it.

- if you need to add something to the path for a single script, you either need to wrap it with a call to env, set it in a wrapper script, or set the path before the entry and reset it afterwards

- you can't use ~ or $HOME in the path, you have to write out the full absolute path. Which is particularly annoying for user crontabs.

Sure, it isn't too hard to work around those, but IMO systemd timers are a better experience, especially since the default uses the same path as all your other services.


Replies

thomashabets2today at 7:48 AM

> - the default value is missing some values you would expect, like /use/local/bin and /usr/sbin for root.

What do you mean by "you would expect", that doesn't also apply to systemd timers? /opt/foo/bin is not in the path. Would you expect that?

And if this is an objective problem, can we just change the cron default PATH?

> - on some distributions (for example Arch Linux) the man page doesn't even say what the default path is, or recommend setting it.

Send a PR. This doesn't seem like an inherent problem.

> - if you need to add something to the path for a single script, you either need to wrap it with a call to env, set it in a wrapper script, or set the path before the entry and reset it afterwards

Or on the line, right?

    * * * * * FOO=bar $HOME/bin/foo.sh
The line can get long, but is this really a problem?

> - you can't use ~ or $HOME in the path, you have to write out the full absolute path. Which is particularly annoying for user crontabs.

This is incorrect. You can definitely use $HOME in user crontabs.

I'm still not seeing something that warrants a rewrite. (except what you did not mention, which is the ability to run "trigger this now" as a missing feature)