为什么 Anacron 需要 $PATH 中命令的完整路径

为什么 Anacron 需要 $PATH 中命令的完整路径

我注意到,从命令行完美运行的脚本在 Anacron 中无法正常工作。通常原因是 Anacron 需要命令的完整路径。有没有办法让 Anacron 使用的 $PATH 与用户或 su 使用的 $PATH 相同?

答案1

根据页面内容,我认为这是在 anacrontab 中的命令之前完成的man 5 anacrontab

环境分配行的格式为:

     VAR = VALUE

  Spaces around VAR are removed.  No spaces around VALUE are allowed (unless you want them to be part of the  value).
  The  assignment takes effect from the next line to the end of the file, or to the next assignment of the same vari‐
   able.

  Empty lines are either blank lines, line containing white-space only, or lines with white-space followed by  a  '#'
   followed by an arbitrary comment.

  You can continue a line onto the next line by ending it with a '\'.

查看文件/etc/anacrontab

# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
HOME=/root
LOGNAME=root

# These replace cron's entries
1   5   cron.daily  run-parts --report /etc/cron.daily
7   10  cron.weekly run-parts --report /etc/cron.weekly
@monthly    15  cron.monthly    run-parts --report /etc/cron.monthly

如您所见,环境变量是在命令之前设置的。

相关内容