How to exit from a server?

Hi,

I am on unix serverA where i have a script called A.sh

more A.sh
echo "Hello"
ssh user1@serverB
echo "Welcome"

After the ssh takes me to serverB; i execute a script on serverB called B.sh

more B.sh
echo " You are serverB"
exit
exit

With the two exit statements on serverB i was expecting that the control would comeback to serverA and that i would exit from serverB. But that did not happen and i had to manually type exit twice to come back to serverA where it then printed Welcome

Which is quite normal as of the little content of b.sh ... int other words it exited on the first exit as we would suppose it should have done and second is never executed...

So, how can i get it to exit from the server.

How? Where?
We see nothing in what you have submitted so we cant help...

If your command/script is part of your ssh command, then when the command/script finishes, so will the ssh and you will be back at ServerA

Consider a script on ServerA

echo "Runs on `hostname`"
ssh ServerB hostname
echo "Back on `hostname"

Does that help, or have I missed the point?

You should get the output:

ServerA
ServerB
ServerA

Robin

After the script A.sh of serverA helps me ssh to ServerB; i manually execute the script on serverB i.e. ./B.sh . What do i have to code inside the B.sh so that it helps exit from serverB back to A.sh on serverA

IF you manually type ./B.sh when it finishes its back to the prompt, where you type exit.. I have not ime for testing now... but you could try

./B.sh ;exit 

or

 ./B.sh && exit 
1 Like

Or - don't execute B.sh but source it: . ./B.sh