• Uncategorized

About shell : SSH-Remotely-run-a-script-and-stay-there

Question Detail

I wish to run a script on the remote system and then wish to stay there.
Running following script:-

ssh [email protected] logs.sh

This do run the script but after that I am back to my host system. i need to stay on remote one. I tried with..

ssh [email protected] logs.sh;bash -l

somehow it solves the problem but still not working exactly as a fresh login as the command:-

ssh [email protected]

Or it will be better if i could include something in my script that would open the bash terminal in the same directory where the script was running. Please suggest.

Question Answer

Try this:

ssh -t [email protected] 'logs.sh; bash -l'

The quotes are needed to pass both commands to ssh. The -t option forces a pseudo-tty allocation.

Discussion

Consider:

ssh [email protected] logs.sh;bash -l

When the shell parses this line, it splits it into two commands. The first is:

ssh [email protected] logs.sh

This runs logs.sh on the remote machine. The second command is:

bash -l

This opens a login shell on the local machine.

The quotes were added above to prevent the shell from splitting up the commands this way.

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.