I'm trying to SSH few servers and trying to get sudo -l
output of each server.
Below is the script I'm executing
#!/bin/bash
serverlist="/tmp/servers"
while IFS=, read -r server netgroup username user
do
ssh -tt -q root@$server sudo -U $username -l < /dev/null
done < "$serverlist"
I have found that -tt
option in this script as the cause of this error. Any thought on this?
Also i have noted that I don't see this error when i execute below command just for 1 server.
ssh -tt -q root@myserver sudo -U cham01 -l
Below is the complete error message I'am getting:
tcgetattr: Inappropriate ioctl for device
tcgetattr: Inappropriate ioctl for device
normally means that some program attempted to do a terminal control operation but its standard I/O streams weren't connected to a terminal. (I know this because tcgetattr
is the name of a C library function that does terminal control operations.)
Now, the whole point of the -tt
option to ssh
is to guarantee that the program run on the remote host is connected to a terminal, and stty
printing out speed 38400 baud; line = 0; -brkint -imaxbel
demonstrates that it was. This is what I get when I run these commands with my servers:
$ ssh myserver stty < /dev/null
stty: 'standard input': Inappropriate ioctl for device
$ ssh -tt myserver stty < /dev/null
speed 38400 baud; line = 0;
-brkint -imaxbel
Connection to myserver closed.
But what you are getting is
$ ssh -tt yourserver stty < /dev/null
tcsetattr: Inappropriate ioctl for device
speed 38400 baud; line = 0;
-brkint -imaxbel
The tcsetattr
error is not coming from stty
. First something tried to do something terminal-related and failed, and then stty
ran successfully.
This suggests a bug in your shell startup scripts, which are doing something that is inappropriate when run "non-interactively", causing you to get this error even though you are running commands connected to a terminal. I can't help you any further, but perhaps this old answer about a similar problem offers some clues.
In this answer I will not propose a solution (I don't know where the error comes from) but, instead, I am going to suggest a powerful instrument to find it!
To understand where the problem comes from you can use the command strace
:
strace ssh -tt -q root@myserver sudo -U cham01 -l < /dev/null
Sure you will realize which one is the system call that causes the error. The shell will prompt all the system calls and, at some point close to the end,you will see something like:
....
ioctl(3, SNDCTL_TMR_START or TCSETS, {B0 -opost -isig -icanon -echo ...}) = -1 ENOTTY (Inappropriate ioctl for device)
....
Here, you can find examples on how to use it.
Suggestion: before the ioctl(...)
system call, there should be an open(...)
system call for the same device. Go in the header file of the device and try to have a look on the different command you can pass it. The problem should be a not recognized command (due maybe to an old version of the device driver used). This is just a suggestion.
export GPG_TTY=$(tty)
From: https://github.com/keybase/keybase-issues/issues/2798#issue-205008630
:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With