user2654241
user2654241

Reputation: 167

Execute script on remote host - output given in local host

I am trying to execute two scripts which are available as sh files on remote host having 755 permissions.

I try callling them from client host as below:

 REMOTE_HOST="host1"
 BOUNCE_SCRIPT="
 /code/sys/${ENV}/comp/1/${ENV}/scripts/unix/stopScript.sh ${ENV};
 /code/sys/${ENV}/comp/1/${ENV}/scripts/unix/startScript.sh ${ENV};
 "

 ssh ${REMOTE_HOST} "${BOUNCE_SCRIPT}"

Above lines are in a script on local host. While running the script on local host, the first command on remote host i.e. stopScript.sh gets executed correctly. It kills the running process which it was inteded to kill w/o any error. However output of second script i.e. startScript.sh gets printed to local host window but the process it intended to start does not start on remote host.

Can anyone please let me know?

  1. Is the way executing script on remote host correct?
  2. Should I see output of running script on remote host locally as well? i.e. on the window of local host?

Thanks

Upvotes: 0

Views: 1722

Answers (3)

R.Sicart
R.Sicart

Reputation: 681

I think cyber-monk is right, you should launch the processes with nohup to create à new independent process. Look if your stop script is killing the right process (the new one included).

Upvotes: 1

cyber-monk
cyber-monk

Reputation: 5570

Prefacing your startScript.sh line with 'nohup' may help. Often times if you remotely execute commands they will die when your ssh session ends, nohup allows your process to live after the session has ended. It would be helpful to know if your process is starting at all or if it starts and then dies.

Upvotes: 1

mousumis
mousumis

Reputation: 383

You could try the -n flag for ssh:

ssh -n $REMOTE_HOST "$BOUNCE_SCRIPT" >> $LOG

The man page has further information (http://unixhelp.ed.ac.uk/CGI/man-cgi?ssh+1). The following is a snippet:

-n Redirects stdin from /dev/null (actually, prevents reading from stdin).

Upvotes: 2

Related Questions