更新时间:2022-06-23 05:29:10
从命令行运行而不是由cron
运行时的脚本的常见问题是环境".关于SO的例子很多,其中包括:
The usual problem with scripts that run from the command line and not when run by cron
is 'environment'. There are many questions on SO where this is exemplified, including:
出于调试目的,请在执行以下操作的cron运行脚本中添加命令/行:
For debugging purposes, add a command/line to the cron-run script that does:
env > /tmp/cron.job
检查其中的PATH是否包含您期望的内容,尤其是是否包含三个程序中每个程序的安装目录(目录).并检查您是否从命令行运行了期望的程序:
Review whether the PATH there includes what you expect, and in particular, whether it includes the directory (directories) where each of the three programs is installed. And do check that you run the programs you expect from the command line:
which vmpstat mpstat iostat
可以合理地猜测,当脚本由cron
运行时,这两个缺失"命令不在PATH的目录中.而cron
为您提供了一个最小的环境;在这方面与at
完全不同.
It is a reasonable guess that the two 'missing' commands are not in a directory on PATH when your script is run by cron
. And cron
gives you a bare minimal environment; it is completely unlike at
in that respect.
另请参阅: