0

My run.sh script errors out when I try to run another script in the background..

Console Error String

./run.sh 30: nohup bash /export/home/myself/bin/mytestprogram &>/dev/null & : No such file or directory
  • can't publish the script because its host machine isn't on the internet.


here is what works

it builds an absolute path to the target program..

such as: Absolute Path to target script

/export/home/myself/bin/mytestprogram

which runs fine manually or through the script... It builds this command line with script variables like so

Bash Script how I build the command string

cmd="${exedir}/${exe}"

and I run this from my script by saying

Bash Script line which Calls the Target command string

"${cmd}"

all that works.. So running the script in the foreground works.


Now what doesn't work, when I try to run the exact same path and command in the background.

I am trying to run:

Run in Background Command String

nohup bash /export/home/myself/bin/mytestprogram &>/dev/null &

which works when I manually past it from the output of my script to the command line. When I manually call this on the command line, it works. My script actually echo's the command to the console and I cut and past it and it works. But when the run.sh script calls same command, it doesn't work?

I build this with the same variables as the above foreground call like so..

How the Background Command String is built

cmd="nohup bash ${exedir}/${exe} &>/dev/null &"

I echo this command to the console like so:

How Background Command String is sent to Console

echo -e "$cmd"

and call it like so..

"$cmd"

again my error message is:

Console Error String

./run.sh 30: nohup bash /export/home/myself/bin/mytestprogram &>/dev/null &
:No such file or directory

Any thoughts?

New contributor
JMS is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
2
  1. The command I think you're looking for is nohup. Not nohub.

  2. You can't do this:

    cmd="nohub bash ${exedir}/${exe} &>/dev/null &"
    "${cmd}"
    

    What that's doing is trying to run a command consisting of the single word nohub bash /export/home/myself/bin/mytestprogram &>/dev/null & - including the spaces and punctuation as part of that single word. The shell will not evaluate the command and split it at spaces.

There are several answers here, for example How can we run a command stored in a variable?, that explain how you can safely build a command and then execute it. Personally I think you're probably better off just running the command when you want to use it rather than putting it into a variable and trying to execute its value.

Your Answer

JMS is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.