10

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?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Switch
  • 131
  • 2
  • 4
  • 13
  • Is mpstat or iostat an alias? Can you run the commands yourself? – Jonathan Leffler Apr 17 '12 at 15:10
  • It's running into problems run under cron; are the 'missing' commands on the PATH when run by cron? – Jonathan Leffler Apr 17 '12 at 15:15
  • I can run the commands by myself. I basically have the same script on 2 different servers with the same settings. I use the cron just to fireoff the script. In fact I just tried running the script by itself and it is working. I wonder if it has to do with running inside the cron> Although it is pretty much the same for the other server and runs inside the cron – Switch Apr 17 '12 at 16:01
  • 2
    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. – Jonathan Leffler Apr 17 '12 at 16:43
  • Thanks Jonathan!!! It turns out including the whole path to the mpstat installation worked. Although I find it weird that the same settings on the second server work without including the entire path. In any case all is responding well now> Thanks again\ – Switch Apr 23 '12 at 14:26
  • In my case this answer by Michael Hampton pointed the direction in transitioning from daemon to nohup and the quotes around arguments: https://serverfault.com/questions/477686/nohup-no-such-file-or-directory – Paul Jul 31 '18 at 16:18

2 Answers2

4

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

For example:

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

LaurentG
  • 11,128
  • 9
  • 51
  • 66
jeremyxu
  • 41
  • 1
3

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:

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:

Community
  • 1
  • 1
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278