Get rid of Pseudo-terminal message when you use ssh with here document

When I send multiple commands over ssh to a Linux or ESXi host using here document, I get this message:

Pseudo-terminal will not be allocated because stdin is not a terminal.

For example:

    $ ssh -q root@esxi.local.example.com  <<EOF
    > date
    > hostname
    > EOF
    Pseudo-terminal will not be allocated because stdin is not a terminal.
    Sun Aug 14 06:01:26 UTC 2016
    esxi.local.example.com

The reason for this is concisely explained here [stackoverflow].

To avoid the Pseudo-terminal message, we can use “ssh -T”

    $ ssh -q -T  root@esxi.local.example.com  <<EOF
    > date
    > hostname
    > EOF
    Sun Aug 14 06:02:10 UTC 2016
    esxi.local.example.com

or pass shell as an argument to ssh.

    $ ssh -q  root@esxi.local.example.com /bin/sh  <<EOF
    > date
    > hostname
    > EOF
    Sun Aug 14 06:02:41 UTC 2016
    esxi.local.example.com

The “-T” optional disables tty allocation

      man ssh
  -T      Disable pseudo-tty allocation.

If you like, you can do the same without using the here document.

$ ssh -q root@linux"
> date
> hostname
> uname -a
> "
Sun Aug 14 01:23:50 CDT 2016
linux_hostname
Linux linux_hostname 2.6.18-411.el5 #1 SMP Thu Jun 2 02:56:21 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux

You can even put the commands in one like separated by semi colons

ssh -q gonzo "date;hostname"

The set of commands is not a great use case for here document, just an example to illustrate the use of here document.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s