ssh calls stty to do things like turn off/on echo. When the terminal stdin device is not what ssh expected you get the stty error. Try simply executing the ssh command making sure it can use the controlling terminal device with stty and using ssh keys:
ssh me@somplace 'my command goes here ' > output_file
# output_file now has your result it in it, so you can read the file to get your variables.
I may be missing something but this has happened to me before and my workaround was okay. Still is.
One caveat - if you are running under ksh (does appear to be in this case) then be sure there are no stty commands in the current directory's .kshrc , that also causes this problem.
The problem with that is, that I run these SSH commands in a while loop and the while loop breaks, when I don't use at least the -n parameter with ssh.
Here is the code block where I get the error.
Your code snippet does not look like what you showed in post #1. Where do you get the error? Is it issued by ssh or by lshwres ? Try changing -T to -t .
Split the problematic code into smaller pieces for a step by step trouble shooting; e.g. run the ssh command alone and check its output, then read a single value from a simple command into a single variable, then go on to more complex stuff. Is the IFS variable set correctly?
The code snippet is already adjusted to jim mcnamara's suggestion, which unfortunately didn't solve the problem.
The error is caused by the ssh -T and -t are doing the absolutely opposite thing.
Anyway, when I use -t , I only get another error.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Which I can relate to.
Running every command for its own on the shell itself works perfectly, the codeblock itself also works as intended, I only get this error message from the ssh .
Running the ssh command on shell is also fine
stty: standard input: Inappropriate ioctl for device
Pseudo-terminal will not be allocated because stdin is not a terminal.
Both outputs, aren't exactly errors, why the ssh command comes back with exit code 0.
I want to understand why this message comes and how I'm able to avoid it.
Like I said: The code is working perfectly, as it is supposed to be, I just receive this message and I try to build the script to avoid it properly and not just suppress it.
When I drop the -n parameter, the while loop will break, which is just how it is supposed to work.
The stty: standard input: Inappropriate ioctl for device message comes, regardless of which command I execute on the remote host, even a date, or test causes it, which is why I think that the ssh is responsible for it.
# ./script.sh
.
.
.
++ for HMC in '${strHMCLIST}'
++ strNILIST=
++ ssh -t hscroot@X.X.X.X 'lssyscfg -r sys -F '\''name type_model serial_num lpar_proc_compat_modes'\'''
++ read N T S P
Connection to X.X.X.X closed.
++ strNAME=XXX
++ strIDENT='XXX*XXX'
++ strNILIST='XXX XXX*XXX\n'
++ strCPUARCH=XXX
++ read strDATE
+++ ssh -t hscroot@X.X.X.X date
stty: standard input: Inappropriate ioctl for device
Pseudo-terminal will not be allocated because stdin is not a terminal.
++ read N T S P
++ echo
Now, it doesn't break, that is. The ssh just eats up all stdin which is redirected from .outlist.tmp , and the while read cleanly finishes on end-of-file. Did you consider using another file descriptor for redirecting its input?
I use MobaXterm, which brings its own SSH client.
Unfortunately, for "security reasons" this Windows Terminalserver is the only connection I have to my UNIX machines.
Well, yes, this works and is an idea I didn't get behind earlier.
Thank you very much!