简体   繁体   English

尝试SSH时设备不正确的ioctl

[英]Inappropriate ioctl for device when trying to SSH

I'm trying to SSH few servers and trying to get sudo -l output of each server. 我正在尝试SSH少量服务器,并尝试获取每个服务器的sudo -l输出。

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. 我发现此脚本中的-tt选项是导致此错误的原因。 Any thought on this? 有什么想法吗?

Also i have noted that I don't see this error when i execute below command just for 1 server. 我也注意到当我仅对1台服务器执行以下命令时,我没有看到此错误。

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

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. tcgetattr: Inappropriate ioctl for device 通常意味着某些程序试图执行终端控制操作,但其标准I / O流未连接到终端。 (I know this because tcgetattr is the name of a C library function that does terminal control operations.) (我知道这tcgetattr是因为tcgetattr是执行终端控制操作的C库函数的名称。)

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 现在,整点-tt选项ssh是保证在远程主机上运行的程序连接到一个终端,并且stty打印输出speed 38400 baud; line = 0; -brkint -imaxbel speed 38400 baud; line = 0; -brkint -imaxbel speed 38400 baud; line = 0; -brkint -imaxbel demonstrates that it was . speed 38400 baud; line = 0; -brkint -imaxbel证明它 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 . tcsetattr错误不是来自stty First something tried to do something terminal-related and failed, and then stty ran successfully. 首先,某些操作尝试执行与终端相关的操作并失败, 然后 stty成功运行。 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. 这表明您的Shell启动脚本中存在一个错误,该错误在“非交互式”运行时做了不当的操作, 即使正在运行连接到终端的命令, 也会导致出现此错误。 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命令:

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: Shell将提示所有系统调用,并且在接近结束的某个时刻,您将看到类似以下内容:

....
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. 建议:在进行ioctl(...)系统调用之前,应针对同一设备进行open(...)系统调用。 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. 这只是一个建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM