0

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

2
  • I tried modifying the script at local host by creating two separate commands out of single command. i.e. instead of running stopScript.sh and startScript.sh from a single BOUNCE_SCRIPT. I created two variables. STOP_SCRIPT=/code/sys/${ENV}/comp/1/${ENV}/scripts/unix/stopScript.sh ${ENV} START_SCRIPT=/code/sys/${ENV}/comp/1/${ENV}/scripts/unix/startScript.sh ${ENV}. However upon running script, it manages to execute only 1st script i.e. stopScript.sh, it runs 2nd script i.e. startScript.sh but the process it tries to start no longer remains started on remote host. any idea what can be wrong? Commented Nov 25, 2013 at 18:00
  • i tried further using command as below ssh -q ${REMOTE_HOST} ${START_SCRIPT} - and that worked. Thank you all for having a look at the issue and providing suggestions. Commented Nov 26, 2013 at 10:50

3 Answers 3

2

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).

Sign up to request clarification or add additional context in comments.

2 Comments

-n just redirected output to a log file as expected. however the startScript.sh is supposed to start a java program. it prints out the pid of java program started but the program itself does not stay started. i am not able to find program for that pid running on remote host.
Have you tried running the script in the background on the remote machine and see if it stays up? "/code/sys/${ENV}/comp/1/${ENV}/scripts/unix/stopScript.sh ${ENV} &"
1

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.

2 Comments

So is it starting and dieing or not starting at all?
Also what is getting printed on std out and err for the process you attempt to start?
1

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.