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.
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.
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.
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).
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 &:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.