-2

I want to redirect ssh welcome message in a file on my local machine. After that I have to run few commands to remote machine using ssh. When I am trying ssh <username>@<hostname> | dd of=FILENAME, this command is writing output to logfile but terminal hangs so the rest of the command execution doesnt happen.

Please help me with redirecting ssh welcome message

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
J197823
  • 1
  • 1
  • 3
    That command doesn't make any sense. You start an interactive session but redirected the output?! You need to actually run a command on the remote server. – Michael Hampton Feb 25 '19 at 15:01

1 Answers1

1

Your SSH session does not hang, it is waiting for input.

The trick is that you need an interactive shell for the welcome message to be displayed. You can accomplish that by sending "logout" to an internal ssh session

echo "logout" |ssh server

Then you only need to pipe the output into a file:

user@client:~$ echo "logout" |ssh server > motd.txt
Pseudo-terminal will not be allocated because stdin is not a terminal.
Warning: No xauth data; using fake authentication data for X11 forwarding.
user@client:~$ cat motd.txt
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-45-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage


 * Canonical Livepatch is available for installation.
   - Reduce system reboots and improve kernel security. Activate at:
     https://ubuntu.com/livepatch

0 packages can be updated.
0 updates are security updates.
Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89