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
nohup error no such file or directory
提问by Switch
I am trying to run a string of nohup
commands to get server statistics.
However I get an error of 'No such file or directory'. Note that the 3 nohup
calls are embedded in a script which is executed through a cron
job. And the first nohup
works 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 cron
is 'environment'. There are many questions on SO where this is exemplified, including:
从命令行运行而不是在运行时运行的脚本的常见问题cron
是“环境”。在 SO 上有很多问题可以举例说明,包括:
- 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?
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 cron
gives you a bare minimal environment; it is completely unlike at
in 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