LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 05-11-2007, 05:33 PM   #1
linux_2007_
Member
 
Registered: Feb 2007
Posts: 80

Rep: Reputation: 15
Questions on "SSH"


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.
 
Old 05-11-2007, 05:35 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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)
 
Old 05-11-2007, 06:51 PM   #3
linux_2007_
Member
 
Registered: Feb 2007
Posts: 80

Original Poster
Rep: Reputation: 15
Thanks Matir
.

Last edited by linux_2007_; 05-12-2007 at 02:41 PM.
 
Old 05-11-2007, 06:54 PM   #4
linux_2007_
Member
 
Registered: Feb 2007
Posts: 80

Original Poster
Rep: Reputation: 15
Are "bash<<<EOF" and the last line "EOF" the exact syntax that I should type and put in the script file?

If you have any advice for my 2nd question as well, that would be a great help.

Thanks.

Last edited by linux_2007_; 05-12-2007 at 02:40 PM.
 
Old 05-11-2007, 10:10 PM   #5
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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.
 
Old 05-12-2007, 02:16 AM   #6
linux_2007_
Member
 
Registered: Feb 2007
Posts: 80

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Matir
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.
 
Old 05-12-2007, 09:02 AM   #7
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SSH issue ""Server unexpectedly closed network connection" Errsta_Fonzarelli Linux - Software 12 05-24-2010 02:35 PM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM
Why does "crond" sleep and "ssh" hung up? Chowroc Linux - Networking 0 01-12-2006 12:24 AM
Two questions, 1 about "GOK" and the other about "Super Karamba" Matt.Ramos Linux - Software 0 07-14-2004 09:57 PM
"socks5" -> "http" proxy protocol, or ssh tunnel to sock5 ? I'm beyond http p vmicho Linux - Networking 2 12-16-2003 05:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration