-1

I need to pass a bash command into another process that needs to do the following:

  1. ssh into a computer. This does not require a password prompt.
  2. set up some environment variables: source path/to/script.sh
  3. launch a gui program that requires (2).

Thus far, I have the following:

ssh -n -f pc-name -XYC nohup source folder/setup_thing.sh; program

For my efforts I get:

nohup: failed to run command `source': No such file or directory
bash: program: command not found

I've tried fixes like this and this and several other similar answers. I can't just put all of these in a bash file and then just call ssh mySever 'nohup bash myscript.sh'.

How to I restructure the above command such that it executes successfully?

  • @Anthon. Better? – Roman Oct 10 '15 at 12:02
  • It's still not clear why you can't just put it all in a script, that would be the obvious way to restructure your solution,without quotes the ; terminates the ssh command, so you are trying to run the GUI locally. Is that what you want ? – X Tian Oct 10 '15 at 12:57
  • @Roman Yes. Adding a real question to your post, allows you to refocus the the attention of the reader to what actually needs to be resolved (especially important after providing contextual information that might or might not be relevant). With less guesswork there is just a higher chance on a working answer. – Anthon Oct 10 '15 at 13:00
  • @XTian. Because I'm working within a much larger framework where doing IO adds unnecessary amount of complexity. And because its possible to do in one line like Archemar has so elegantly shown. – Roman Oct 10 '15 at 16:20
2

I would try

 ssh -n -f pc-name -XYC ". folder/setup_thing.sh; nohup  program &"
  • . folder/setup_thing.sh will init variable from setup_thing.sh.
  • nohup program & will run program in backgroup, and return from ssh (due to nohup)"
  • Perfect. Thanks. Though I don't need to run it as a background process with &. – Roman Oct 10 '15 at 10:49
  • 1
    then skip both nohup and &. – Archemar Oct 10 '15 at 10:53
  • I know this is a question all of its own, but I can't find an easy reference to what these arguments mean (linuxcommand.org/man_pages/ssh1.html doesn't explain any of these). What are they? – Roman Oct 10 '15 at 11:03
  • @Roman: Because they aren't ssh related. They're shell related--just like your entire question, really. – Flimzy Oct 10 '15 at 12:14
1

I tried this:

nohup ssh -n -f pc-name -XYC "source folder/setup_thing.sh; program"

and it worked. Though it does tell me that

nohup: ignoring input and redirecting stderr to stdout
  • Well, then, leave off the nohup! – G-Man Oct 10 '15 at 14:12

Your Answer

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.