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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10193824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:50:33  来源:igfitidea点击:

nohup error no such file or directory

linuxshellunixnohup

提问by Switch

I am trying to run a string of nohupcommands to get server statistics. However I get an error of 'No such file or directory'. Note that the 3 nohupcalls are embedded in a script which is executed through a cronjob. And the first nohupworks but the other 2 return an error. Ironically enough, when run on a different server, the script works fine.

我正在尝试运行一串nohup命令来获取服务器统计信息。但是,我收到错误消息“没有这样的文件或目录”。请注意,这 3 个nohup调用嵌入在通过cron作业执行的脚本中。第一个nohup有效,但其他两个返回错误。具有讽刺意味的是,当在不同的服务器上运行时,该脚本运行良好。

  • Commands

    nohup vmpstat -a -n 60 1000 > myvmstats
    
  • (works)

    nohup mpstat -P ALL 1 1000 > mympstats
    
  • (returns: nohup cannot run command mpstat: no such file or directory)

    nohup iostat -t -x 60 1000 >myiostats
    
  • (returns: nohup cannot run command iostat: no such file or directory)

  • 命令

    nohup vmpstat -a -n 60 1000 > myvmstats
    
  • (作品)

    nohup mpstat -P ALL 1 1000 > mympstats
    
  • (返回:nohup 无法运行命令mpstat:没有这样的文件或目录)

    nohup iostat -t -x 60 1000 >myiostats
    
  • (返回:nohup 无法运行命令iostat:没有这样的文件或目录)

Any idea what's wrong?

知道出了什么问题吗?

采纳答案by Jonathan Leffler

The usual problem with scripts that run from the command line and not when run by cronis 'environment'. There are many questions on SO where this is exemplified, including:

从命令行运行而不是在运行时运行的脚本的常见问题cron是“环境”。在 SO 上有很多问题可以举例说明,包括:

For debugging purposes, add a command/line to the cron-run script that does:

出于调试目的,将命令行/行添加到执行以下操作的 cron-run 脚本:

env > /tmp/cron.job

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:

检查那里的 PATH 是否包含您期望的内容,特别是它是否包含安装了三个程序中的每一个的目录(目录)。并检查您是否从命令行运行了您期望的程序:

which vmpstat mpstat iostat

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 crongives you a bare minimal environment; it is completely unlike atin that respect.

当您的脚本由cron. 并cron为您提供一个最小的环境;at在这方面完全不同。

See also:

也可以看看:

回答by jeremyxu

I think you should give the relative/absolute path of you program

我认为你应该给出你程序的相对/绝对路径

For example:

例如:

nohup ./****.sh > /home/user/test.txt

nohup ./****.sh > /home/user/test.txt