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

stty: : Invalid argument Using SSH

1,762 views
Skip to first unread message

John Doe

unread,
Sep 27, 2008, 12:19:26 PM9/27/08
to
In a script, I was using SSH to run a command on a remote server. I
got the message "stty : : invalid argument." It took me a while to
figure out why. An interactive shell reads commands from user input on
a tty. If you're executing ssh inside a script to run a command on
another server, ssh logs into the server as a specific user, and
executes the command on the server in a non-interactive shell.

Command shells in the sh family execute ~/.profile and ~/.bash_profile
once at login, and ~/.kshrc and ~/.bashrc when ever a new shell
starts. Command shells in the csh family execute the ~/.login on
login, and the ~/.cshrc when ever a new shell starts. When a user logs
into a server the shells reads these initialization files: ~/.kshrc,
~/.bashrc, or ~/.cshrc followed by the ~/.profile, ~/.bash_profile or
~/.login depending on the shell.

.profile, .bash_profile, .login: used to identify the terminal and set
the erase character

.cshrc, .kshrc, .bashrc: used to set shell variables and aliases

If you see "stty : : Invalid Argument," it means your ssh command
logged into the remote server (non-interactive) and initialized the
shell, but encountered stty in one of the scripts above. It's a non-
interactive shell, there is no control terminal.

Look in the scripts mentioned above for a stty. You'll find it because
this is why you're getting the "stty : : Invalid Argument." You can
remove the line, or check for interactive or non-interactive:

if [ -t 0 ]; then
echo interactive
stty erase ^H
else
echo non-interactive
fi

-t fd - True if file descriptor fd is open and refers to a terminal

Joachim Schmitz

unread,
Sep 28, 2008, 5:55:44 AM9/28/08
to

Or you just discard the error messages

stty erase ^H 2>/dev/null

Bye, Jojo


S P Arif Sahari Wibowo

unread,
Sep 28, 2008, 9:35:41 AM9/28/08
to
On Sat, 27 Sep 2008, John Doe wrote:
> if [ -t 0 ]; then
> echo interactive
> stty erase ^H
> else
> echo non-interactive
> fi

Thanks! How reliable is this? I mean, is it likely for and
non-interactive shell have its 0 fd redirected to tty, and
conversely for an interactive shell have its 0 fd redirected to
a non-tty?

There is other way to check for interactivity:

case $- in
*i* ) INTERACTIVE=1 ;;
esac

And this apparently works (although no idea what 255 fd for):

if [ -t 255 ]; then INTERACTIVE=1 ; fi


--
(stephan paul) Arif Sahari Wibowo
_____ _____ _____ _____
/____ /____/ /____/ /____
_____/ / / / _____/ http://www.arifsaha.com/

John Doe

unread,
Sep 28, 2008, 1:53:41 PM9/28/08
to

Awesome, I'll have to try this. The redirection that you mentioned
could be done, but why? I'm assuming, I guess, a normal baseline for
initializing a shell.

John Doe

unread,
Sep 28, 2008, 1:54:25 PM9/28/08
to
On Sep 28, 4:55 am, "Joachim Schmitz" <nospam.j...@schmitz-digital.de>
wrote:

I know the error message can just be discarded, but I wrote this
thread to try to educate others that wonder why they're seeing the
message.

larrycohen28

unread,
Feb 1, 2014, 6:04:55 AM2/1/14
to
You cannot just discard the error message. I'm trying to use stty -echo on a remote server using ssh, to have a user change their password on an ldap server. The password is displaying when I type it. I type the same command at the command line on the server and I don't even need the stty -echo, it just doesn't display the password. Trying to add stty -echo not only doesn't work, but it displays the same error above.


larrycohen28

unread,
Feb 1, 2014, 6:05:07 AM2/1/14
to
Also, there is no stty in any of .bashrc or .profile or any other . file in the user's home directory, that they are logging in as. I also checked in /etc/profile.


Casper H.S. Dik

unread,
Feb 1, 2014, 7:11:58 AM2/1/14
to
You don't have a remote tty, you only have a local tty and you didn't
disable the echo there.

You ar eprobably starting ssh with a command; that means that, by default,
sshd won't allocate a tty. You may want to read the ssh manual;
I believe the option you need is "-t".

Casper
0 new messages