nohup error no such file or directory

▼魔方 西西 提交于 2019-12-22 05:24:13

问题


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
    
  • (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)

Any idea what's wrong?


回答1:


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?

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

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:

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.

See also:

  • 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?



回答2:


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

For example:

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



来源:https://stackoverflow.com/questions/10193824/nohup-error-no-such-file-or-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!