Too*_*rot 1 cron environment-variables
我发现设置我的 crontabPATH=/home/toothrot/bin
有效,但
$HOME/bin
没有。我检查了一下,$HOME
设置是否符合预期。cron 不扩展环境变量吗?我尝试通过调用路径中的脚本来使用它。
* * * * * fetchmail
Run Code Online (Sandbox Code Playgroud)
PATH
当设置为完整显式路径时,此脚本会写入日志文件,但在使用 时不会$HOME
写入日志文件,可能是因为在后一种情况下它不会运行。
您没有指定您正在使用的 cron 实现,但至少在基于 Debian 的系统(它源自 Vixie cron IIRC)中没有指定。从man 5 crontab
:
An active line in a crontab will be either an environment setting or a\n cron command. The crontab file is parsed from top to bottom, so any\n environment settings will affect only the cron commands below them in\n the file. An environment setting is of the form,\n\n name = value\n\n where the spaces around the equal-sign (=) are optional, and any subse\xe2\x80\x90\n quent non-leading spaces in value will be part of the value assigned to\n name. The value string may be placed in quotes (single or double, but\n matching) to preserve leading or trailing blanks. To define an empty\n variable, quotes must be used. The value string is not parsed for envi\xe2\x80\x90\n ronmental substitutions or replacement of variables, thus lines like\n\n PATH = $HOME/bin:$PATH\n\n will not work as you might expect. And neither will this work\n\n A=1\n B=2\n C=$A $B\n\n There will not be any subsitution for the defined variables in the last\n value.\n\n An alternative for setting up the commands path is using the fact that\n many shells will treat the tilde(~) as substitution of $HOME, so if you\n use bash for your tasks you can use this:\n\n SHELL=/bin/bash\n PATH=~/bin:/usr/bin/:/bin
Run Code Online (Sandbox Code Playgroud)\n