Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ssh with here document and 'stdin: is not a tty' error message

0 views
Skip to first unread message

Javi Barroso

unread,
Nov 5, 2008, 6:35:03 AM11/5/08
to
Hi,

I have next script:

for dom0 in host1 host2
do
if nc -z $dom0 22;
then
ssh root@$dom0 <<EOS
[ -f /usr/sbin/xm ] &&
xm info | awk '
BEGIN { printf "$dom0 "; }
/total_memory/ { printf "%d ", \$3}
/free_memory/ { print \$3 }'
EOS
else
echo "$dom0 no responde"
fi
done

When I run it:
$ ./script
host1 4093 181
stdin: is not a tty
host2 4093 145

If I change here document to doubled quoted string it works without
warning

How can I disable this warnings ? Any workaround?

Thanks

Michael Schindler

unread,
Nov 5, 2008, 8:11:18 AM11/5/08
to

Hi javi,

try
ssh -T root@$dom0

Javi Barroso

unread,
Nov 5, 2008, 11:07:27 AM11/5/08
to
On 5 nov, 14:11, Michael Schindler <Michael.Schind...@materna.de>
wrote:

> Hi javi,
>
> try
> ssh -T root@$dom0
I tried it too, the same issue

Thanks for your time

Regards

Иван

unread,
Nov 5, 2008, 11:21:20 AM11/5/08
to

It's got to do with "t", in lower case.
man ssh said:
"
-T Disable pseudo-tty allocation.

-t Force pseudo-tty allocation. This can be used to execute
arbitrary screen-based programs on a remote machine, which can be very
useful, e.g., when implementing menu services. Multiple -t options
force tty allocation, even if ssh has no local tty.
"

Javi Barroso

unread,
Nov 5, 2008, 12:03:23 PM11/5/08
to

with -t I get again the same issue.

with -t -t I get:
tcgetattr: Inappropriate ioctl for device
and then it seems like understand "\t" into host1 (it showed me about
host1 files auto-complete feature)

Thanks

Icarus Sparry

unread,
Nov 5, 2008, 12:12:09 PM11/5/08
to

What shell does "root" have on the two remote hosts?
Typically this message comes from a command being placed in a shell
startup file (e.g. ~root/.bashrc on the remote hosts) that should not be
there. The most common is something like "stty erase ^?".

Javi Barroso

unread,
Nov 5, 2008, 1:06:47 PM11/5/08
to
Hi Icarus and list,

It is running bash on both servers.

With your tip my problem changed to:

$ ssh root@host1 <<EOF
> echo \$PS1
> EOF
$ ssh root@host2 <<EOF
> echo \$PS1
> EOF


stdin: is not a tty

\h:\w\$

But I can't find which is te diff between root@host1 bash session
files and root@host2

I tried to compare:
bash.bashrc bash_completion .bash_history .bash_profile .bashrc
profile

And too /etc/pam.d directory ( I think I compared all /etc/ dir with
meld)

Only export sentences (to set environment variables) are different

In ~/.bashrc i tried comment:
export PS1='\h:\w\$ '

but the result was:
$ ssh root@host2 <<EOF
> echo \$PS1
> EOF


stdin: is not a tty

I tried ssh with pipe, and too appears the same issue:
echo "ls" | ssh root@host2


stdin: is not a tty

echo "ls" | ssh root@host1
ok

Have you got any tip more?

Thanks you!

Javi Barroso

unread,
Nov 5, 2008, 1:38:44 PM11/5/08
to

And it were on .bash_profile who exists on host1 and not in host2 !!!

on my .profile reads:
mesg n

and this command was who tell 'is not a tty'

I didn't know about if .bash_profile exist .profile is not read.

So, should I modify in .profile to:
mesg n 2> /dev/null

Or are there any other better tip?

Thank you!

Иван

unread,
Nov 5, 2008, 2:57:11 PM11/5/08
to
Couldn't you `scp` the awk script on each server?

#!/bin/bash
#name: awk_script

[ -f /usr/sbin/xm ] &&
xm info | awk '
BEGIN { printf "$dom0 "; }
/total_memory/ { printf "%d ", $3}
/free_memory/ { print $3 }'

---
and then

#!/bin/bash
#name: "client"_script

if nc -z $dom0 22;
then

ssh root@$dom0 awk_script


else
echo "$dom0 no responde"
fi

---
?

Javi Barroso

unread,
Nov 5, 2008, 4:02:56 PM11/5/08
to

Then If you have n servers, you need to maintain n scripts (or push
any changes on the script to them from some script).

I used your method with others scripts

I don't know which is the prefer/best method

Do you recommend cfengine or puppet for doing such things ?

Icarus Sparry

unread,
Nov 6, 2008, 12:16:05 PM11/6/08
to

You could also try replacing the line with

[ -t 0 ] && mesg n

to test if the input is a terminal.

0 new messages