且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

nohup错误没有这样的文件或目录

更新时间: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:

  • Perl script works but not when via cron
  • Why does my command line not run from cron?
  • Bash script not executing in cron correctly
  • How can I set environment variables that crontab will use?

出于调试目的,请在执行以下操作的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.

另请参阅:

  • Crontab and testing a command to be executed
  • How do I add pre-hook and post-hook scripts that run before all of my cron jobs?