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? Oct 17 '20 at 18:36
  • @glennjackman there is no difference in the output when -t is added as option of ssh
    – chmike
    Oct 18 '20 at 11:49
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. Oct 18 '20 at 0:45
  • @AndyDalton option -t doesn't change the output
    – chmike
    Oct 19 '20 at 10:46
  • 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
    Oct 19 '20 at 12:01
  • @fra-san how do you explain that the >> /dev/null hides everything except the stdin line ?
    – chmike
    Oct 19 '20 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
    Oct 19 '20 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.