f



stty: : Invalid argument Using SSH

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
1
John
9/27/2008 4:19:26 PM
comp.unix.shell 15484 articles. 2 followers. Post Follow

7 Replies
8406 Views

Similar Articles

[PageSpeed] 11

John Doe wrote:
> 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

Or you just discard the error messages

stty erase ^H 2>/dev/null

Bye, Jojo 


-1
Joachim
9/28/2008 9:55:44 AM
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/
0
S
9/28/2008 1:35:41 PM
On Sep 28, 8:35=A0am, S P Arif Sahari Wibowo <arifs...@yahoo.com> wrote:
> On Sat, 27 Sep 2008, John Doe wrote:
> > if [ -t 0 ]; then
> > =A0 echo interactive
> > =A0 stty erase ^H
> > else
> > =A0 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
> =A0 =A0*i* ) =A0 INTERACTIVE=3D1 ;;
> esac
>
> And this apparently works (although no idea what 255 fd for):
>
> if [ -t 255 ]; then INTERACTIVE=3D1 ; fi
>
> --
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (stephan paul=
) Arif Sahari Wibowo
> =A0 =A0 _____ =A0_____ =A0_____ =A0_____
> =A0 =A0/____ =A0/____/ /____/ /____
> =A0 _____/ / =A0 =A0 =A0/ =A0 =A0/ _____/ =A0 =A0 =A0http://www.arifsaha.=
com/

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.
0
John
9/28/2008 5:53:41 PM
On Sep 28, 4:55=A0am, "Joachim Schmitz" <nospam.j...@schmitz-digital.de>
wrote:
> John Doe wrote:
> > 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
> > =A0 echo interactive
> > =A0 stty erase ^H
> > else
> > =A0 echo non-interactive
> > fi
>
> > -t fd - True if file descriptor fd is open and refers to a terminal
>
> Or you just discard the error messages
>
> stty erase ^H 2>/dev/null
>
> Bye, Jojo

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.

0
John
9/28/2008 5:54:25 PM
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.
0
2/1/2014 11:04:55 AM
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.
0
2/1/2014 11:05:07 AM
larrycohen28 <larrycohen28@gmail.com> writes:

>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.

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
Casper
2/1/2014 12:11:58 PM
Reply: