Script to ssh to remote server

Hi All,

I need to prepare a script.

Description:

Currently i am in server "x(ubuntu os)", here i need to develop a script to ssh to another server "y(ubuntu os)", i have password less authentication to "y". i have done the below

#!/bin/bash
#ssh to the server "y" and confirming i am in "y"
ssh y | echo "$hostname"
-
-
-

once i execute the above script..it is getting structed.. Mainly i want to execute some commands and i want to come out to my old server "x" after executing the script.

Kindly suggest me to finish this script effectively.

Thanks a lot.

You can copy the file you want to execute and call it from x.

scp commands.sh y:/user/

In script :

ssh y "sh /user/commands.sh"

(Or)

you can sepcify the commands you want to run in the below format

ssh y "hostname"

You're not stuck - the session has issued its prompt, which you cannot see due to redirection, and is waiting for your (interactive) command(s).
And, be sure what you want: echoing the variable HOSTNAME (all uppercase) or running the command hostname (all lower)?