[SOLVED] my shell Script stops after doing ssh to remote server
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
my shell Script stops after doing ssh to remote server
Hi,
Could please anyone help me with my script! My Linux version is uname -a
Linux Hostname 2.6.18-164.6.1.el5 #1 SMP Tue Oct 27 11:28:30 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
I have done the keygen part and while logging through script it doesn't ask for any password. But after doing ssh, the scripts just logs into the remote server and not processing further. My script goes likes this.....
[START MY_SCRIPT]
#!/bin/bash
ssh remote-host
retVal=$?
if [ "$retVal" -eq "0" ]; then
cd /apps ;
fi
echo 'Script Completed' ;
[END MY_SCRIPT]
Basically it's not able to get into the /apps path.
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,672
Rep:
Isn't the problem here that the script is running on the local host, so once you ssh into the remote host it suspends until you return? At least that's what happens when I try this.
Edit: I was wondering how this could be done myself and I came across this, which may be useful: http://stackoverflow.com/questions/3...remote-machine
@catkin, nice thought, but still it didn't worked.
The ssh command is opening a new shell. Your script is still stuck in the old shell running the ssh command.
Think about it this way...
If you were at the terminal, and typed ssh, you would then be connected to the other computer. You could then do whatever you wanted, run whatever you wanted, etc. When you typed "exit", your ssh command would end and it would drop you back to the previous shell. THIS is what your script is waiting for. At this point your script would run its next command, "retVal=$?".
Your script will not continue on to the retval, or the cd, etc., until the ssh command has terminated. The ssh command will not terminate until you FINISH whatever it is you are doing on the other machine and return back to the original terminal.
Your script is not stopping or getting stuck after running the ssh, it's simply waiting for the ssh to exit so that it can continue running the script.
Hopefully that makes sense.
Last edited by suicidaleggroll; 05-11-2012 at 09:54 AM.
@uhelp, it's returning value as 0.
@273, thanks for the wonderful link. It solved my problem.
Now, i will be writing two scripts in the local machine.
will be having a wrapper script will do the necessary stuff in the remote-host.
The link which @273 mentioned had something like this....
ssh root@MachineB 'bash -s' < local_script.sh
You shouldn't have to copy the script to the remote server to run it.
So, i will have wrapper script which will solve my problem.
[START MY_SCRIPT]
#!/bin/bash
ssh remote-host 'bash -s' < main_script.sh
[END MY_SCRIPT]
Thanks a lot for all your inputs... Very much appreciated. I thought my problem would take some time to get solved, but amanzingly it got solved within few hours... Thanks again..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.