Re: : Invalid argument Using SSH



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


.