LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-13-2009, 07:21 PM   #1
bits
LQ Newbie
 
Registered: Aug 2009
Posts: 1

Rep: Reputation: 0
ssh's command mode


Hi,

I want to use ssh to execute a command and to wait endlessly to log everything (in file) that comes as a stream of the connected server.

But unfortunately, in the manual its written "If command is specified, it is executed on the remote host instead of a login shell"

So what happens is that when I specify my command:

ssh user@server "my_command"

It executed the command and the flow of execution returns to bash shell. So basically my session ends right after the command is executed. This happens only in case I specify command in the command line. If I login into ssh manually and then type "my_command", then the session doesn't end.

I want the ssh not to exit, because after "my_command" executes, I want to capture everything in the session.


Does anyone know a way out of this problem?

thanks,
 
Old 08-13-2009, 07:36 PM   #2
fordeck
Member
 
Registered: Oct 2006
Location: Utah
Posts: 520

Rep: Reputation: 61
Have you tried redirecting the output to a file? An example would be:

Code:
ssh user@server "my_command" > filename
This would send the output to "filename" on your local machine.

Let us know if this is what you are looking for?

Regards

Fordeck
 
Old 08-13-2009, 07:37 PM   #3
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,604
Blog Entries: 25

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Hi,

Welcome to LQ!

Quote:
Originally Posted by bits View Post
Hi,

I want to use ssh to execute a command and to wait endlessly to log everything (in file) that comes as a stream of the connected server.

But unfortunately, in the manual its written "If command is specified, it is executed on the remote host instead of a login shell"

So what happens is that when I specify my command:

ssh user@server "my_command"

It executed the command and the flow of execution returns to bash shell. So basically my session ends right after the command is executed. This happens only in case I specify command in the command line. If I login into ssh manually and then type "my_command", then the session doesn't end.

I want the ssh not to exit, because after "my_command" executes, I want to capture everything in the session.


Does anyone know a way out of this problem?

thanks,
I'm not sure about what you are wanting to do? You state that if you login via ssh manually and submit your command on cli every thing is joy. Why not just capture at the time of the current session?

Your example states to 'ssh user@server "my_command", so everything is going as you have instructed.

Quote:
excerpt 'man ssh';

DESCRIPTION
ssh (SSH client) is a program for logging into a remote machine and for
executing commands on a remote machine. It is intended to replace rlogin
and rsh, and provide secure encrypted communications between two
untrusted hosts over an insecure network. X11 connections and arbitrary
TCP ports can also be forwarded over the secure channel.

ssh connects and logs into the specified hostname (with optional user
name). The user must prove his/her identity to the remote machine using
one of several methods depending on the protocol version used (see
below).
 
Old 08-13-2009, 07:38 PM   #4
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,495

Rep: Reputation: 193Reputation: 193
Did you try:

ssh user@server "my_command &"

The ampersand at the end should background the task and return you to a bash prompt on the remote machine while it runs. At least that's my hope; have never done this myself over ssh but the theory seems sound. See this article on backgrounding with &:

http://lowfatlinux.com/linux-processes.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple ssh's running protected by tcpwrappers -- but nmap reports different results M_F_H Linux - Security 2 01-26-2009 07:53 PM
command to download the files in command mode. bruse Solaris / OpenSolaris 3 01-12-2006 09:10 AM
lp command with compress mode zita Linux - General 2 10-06-2005 01:36 PM
sleep mode command? uv1 Linux - Newbie 1 09-15-2004 11:38 AM
anything to improve ssh's reliability? clockworks Linux - Software 3 02-05-2004 11:56 AM


All times are GMT -5. The time now is 02:17 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration