Switch
Switch

Reputation: 141

nohup error no such file or directory

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.

Any idea what's wrong?

Upvotes: 11

Views: 62105

Answers (3)

realWorldCoder
realWorldCoder

Reputation: 21

I came across this trying to nohup a python script.

In case anyone has this situation and in case the abovementioned answer by jeremyxu (10 years ago) doesn't fix your issue, linux needs the full path of the python folder as well.

  1. get the full path

which -a python3

  1. sudo access to pthon

sudo nohup /usr/local/bin/python3.10 script.py

Upvotes: 1

jeremyxu
jeremyxu

Reputation: 41

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

For example:

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

Upvotes: 4

Jonathan Leffler
Jonathan Leffler

Reputation: 753695

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:

Upvotes: 3

Related Questions