Exiting the Remote server after script execution

Hi All ,

I'm running a script abc.sh in server "host1" shown as below :


#! /bin/bash

sh stop.sh

ssh user@$host2 "/home/user/prod_work/xyz.sh; 

sh start.sh

The problem I am facing is , the control is not passed to host1 after executing the script "xyz.sh" in host2 .

How to exit the session in host2 after executing the script xyz.sh ??

Thanks,
Pradeep

is working ?

"/home/user/prod_work/xyz.sh;

There's either one double quote too many or one too few... anyhow, the shell should complain.

Sorry..I actually pasted the code wrong ..It is

ssh user@$host2 "/home/user/prod_work/xyz.sh"

But even then the issue remains .

  • what about contents of your script ?
# cat /home/user/prod_work/xyz.sh
  • your ssh connection passwordless ?

What do you mean by 'return control'? What do you expect to happen? What happens?

Yes , the ssh connection is passwordless . I achieved that using the below :

SSH login without password

When I execute abc.sh in server "host1" , the shell script is executed till

ssh user@$host2 "/home/user/prod_work/xyz.sh" , but hangs after that . It does not continue to execute the next line (sh start.sh ) in host1 until I press Ctrl+C . That is what I mean by returning control .

Thanks,
Pradeep

Is there any reason why you don't want to show the content of /home/user/prod_work/xyz.sh as ygemici asked in post # 5?

Yes . Sorry... I'm not in a position to show the script for security reasons but it is a simple script only and it is successfully executed nevertheless .

Thanks,
Pradeep

That's fine, I was wondering because that would had helped. No worries.
It appears that the content of the script is at fault.

---------- Post updated at 10:07 PM ---------- Previous update was at 09:52 PM ----------

Forgive me if this question sounds very simple.
Have you tried with another script, perhaps with just a ls or echoing something?

Hi Aia ,

Thanks for the replies . I have got it working by directing the script to /dev/null (solution got from unix.com forum ).


ssh user@$host2 "/home/user/prod_work/xyz.sh > /dev/null"

But , not sure about the logic though .

Thanks,
Pradeep

It might be better to redirect /home/user/prod_work/xyz.sh to /dev/null, to fix it on the remote side, instead of the local side. Less round-trip, and saves you one stream if you ever need it later.

Thanks . Will try the same .

Regards,
Pradeep