Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
I am writing a script file in linux SUSE os. One line of this script is SSH in order to connect to a remote server. I can do that and the connection is made. Now I have 2 questons:
1. How can I run a remote command (I mean automatically)?
2. How can I keep this connection "open" and go to the next line in the script file (to run the next command)?
I appreciate any help or advice on these, I really need them.
If you want to run a whole batch of commands via SSH, you could do something like:
Code:
ssh user@remote bash<<<EOF
command1
command2 with args
command3
EOF
This spawns a bash shell on the remote system and passes it those commands. You may need the -t option to SSH, sometimes I have, sometimes I haven't. (It depends on the SSH version)
There was a typo in my original post, it's supposed to be "<<", not "<<<". My apologies.
You can replace both instances of EOF with any string that is the same, though EOF is a convention for "End of File".
This will continue and allow multiple commands to be executed on the remote system. If you want to mix local and remote execution, it will be much more complex. Perhaps you can provide an example if this does not work for you.
There was a typo in my original post, it's supposed to be "<<", not "<<<". My apologies. This will continue and allow multiple commands to be executed on the remote system.
No problem, actually I noticed a little after I posted my message. My batch file including several "remote" commands works very well now.
Quote:
Originally Posted by Matir
If you want to mix local and remote execution, it will be much more complex. Perhaps you can provide an example if this does not work for you.
Regarding my 2nd question, all I need is to run SSH to connect to a remote server and keep the connection open as I need to run a software which although is installed on my local PC, for it to be excecuted, it needs license checking and that is on the remote server (I should mention that I have permission from the software producer and the remote server owner both, so it is totally legal, but getting all this working is my own resposibility). As such the script file will be something like this:
...
ssh user@remote
---->> now we are in the remote server (can see the prompt)
---->> then, here I need to run the software installed on my computer without closing the connection (if it gets closed, clearly we are back on the local machine, but the program cannot be run).
In other words, the connection has to be kept on in the background while going back to the local PC for executing the software. I have heard there is a definite solution for it but could not find any answer yet.
I hope this makes it a bit clearer. Any advice?
Thanks
.
Last edited by linux_2007_; 05-12-2007 at 02:42 PM.
You'll probably need to add a port-forward or something similar, but look into the -f option to ssh. You might need to split the execution of remote commands and the port forwarding into two ssh sessions (or get much more complex in your scripting).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.