0

The problem is with a Debian Jessie server.

I run a remote command with ssh like the following example.

#! /bin/bash
ssh root@srv01  << 'STOP_SERVER'
    touch /tmp/testFile
STOP_SERVER

This works except that I get a lot of output that I don’t want. Here is an example with sensible information replaced by stars.

root@home:~# ./test.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.
Linux srv01.***.*** 3.14.32-xxxx-grs-ipv6-64 #5 SMP Wed Sep 9 17:24:34 CEST 2015 x86_64 GNU/Linux

server    : ***
ip        : ***
hostname  : srv01.***.***

stdin: is not a tty

If I change the script to the following

#! /bin/bash
ssh root@srv01  << 'STOP_SERVER' >> /dev/null
    touch /tmp/testFile
STOP_SERVER

I get the following output

root@home:~# ./test.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.
stdin: is not a tty

If I add the option -q to the ssh command I get

root@home:~# ./test.sh
stdin: is not a tty

And this is where I’m stuck because I don’t know how to rewove stdin: is not a tty.

I wish I could avoid output redirect to /dev/null. It’s just the login messages that I don’t want to see.

2
  • What happens if you use ssh -t? Commented Oct 17, 2020 at 18:36
  • @glennjackman there is no difference in the output when -t is added as option of ssh
    – chmike
    Commented Oct 18, 2020 at 11:49

1 Answer 1

0

I just found a fix.

Instead of writing

#! /bin/bash
ssh root@srv01  << 'STOP_SERVER'
    date
    touch /tmp/testFile
STOP_SERVER

write the following

#! /bin/bash
ssh root@srv01  '
date
touch /tmp/testFile
'

No problems anymore.

5
  • Also take a look at the -t option for ssh. Commented Oct 18, 2020 at 0:45
  • @AndyDalton option -t doesn't change the output
    – chmike
    Commented Oct 19, 2020 at 10:46
  • 1
    Note that those two snippets do slightly different things: the first runs a remote login, non-interactive shell, while the second runs a remote non-login, non-interactive shell (i.e. doesn't source .bash_profile or .profile or whatever is applicable, also depending on the remote user's default shell). Hence, the environments your commands are run in will likely differ in the two cases. The "stdin: is not a tty" message seems to be printed by your remote shell's initialization file; an alternative way to prevent it from being sourced is ssh user@host bash -s <<EOT ....
    – fra-san
    Commented Oct 19, 2020 at 12:01
  • @fra-san how do you explain that the >> /dev/null hides everything except the stdin line ?
    – chmike
    Commented Oct 19, 2020 at 19:54
  • 1
    >>/dev/null redirects standard input on the local side. "stdin: is not a tty" is probably printed to standard error (on the remote host and, consequently, by the local ssh as well), >/dev/null 2>&1 should let you get rid of it.
    – fra-san
    Commented Oct 19, 2020 at 20:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .