nohup错误没有这样的文件或目录 [英] nohup error no such file or directory

查看:909
本文介绍了nohup错误没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行nohup命令字符串以获取服务器统计信息. 但是,我收到没有这样的文件或目录" 的错误.请注意,这3个nohup调用被嵌入在通过cron作业执行的脚本中.并且第一个nohup有效,但是其他2返回错误.具有讽刺意味的是,当在其他服务器上运行时,脚本可以正常工作.

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.

  • 命令

  • Commands

nohup vmpstat -a -n 60 1000 > myvmstats

  • (有效)

  • (works)

    nohup mpstat -P ALL 1 1000 > mympstats
    

  • (返回:nohup无法运行命令mpstat:没有此类文件或目录)

  • (returns: nohup cannot run command mpstat: no such file or directory)

    nohup iostat -t -x 60 1000 >myiostats
    

  • (返回:nohup无法运行命令iostat:没有此类文件或目录)

  • (returns: nohup cannot run command iostat: no such file or directory)

    你知道怎么了吗?

    推荐答案

    从命令行运行而不是由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?

    这篇关于nohup错误没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆