Gok*_*kul 12 bash ssh shell-script
下面是脚本。
我想登录几台服务器并检查内核版本。
#!/bin/bash
#input server names line by line in server.txt
cat server.txt | while read line
do
sshpass -p password ssh root@$line << EOF
hostname
uname -r
EOF
done
Run Code Online (Sandbox Code Playgroud)
我希望输出像..
server1_hostname
kernel_version
server2_hostname
kernel_version
Run Code Online (Sandbox Code Playgroud)
等等..
我在 server.txt 中用大约 80 个服务器运行了这个脚本
我得到的输出就像......
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
========================================================================
================================ WARNING ===============================
========================================================================
This system is solely for the use of authorized personnel. Individuals
using this system are subject to having some or all of their activities
monitored and recorded. Anyone using this system expressly consents to
such monitoring and is advised that any unauthorized or improper use of
this system may result in disciplinary action up to and including
termination of employment. Violators may also be subject to civil and/or
criminal penalties.
========================================================================
Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell.
xxxxdev01
2.6.32-431.23.3.el6.x86_64
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Run Code Online (Sandbox Code Playgroud)
在这里,我只有 1 台主机的输出,这xxxxdev01也带有 ssh 横幅和其他警告。
我需要所有其他主机的输出并且没有 ssh 横幅..这里出了什么问题?
Ken*_*ter 13
我无法告诉您为什么没有从hostname和uname命令获得预期的输出,但我可以帮助处理无关的文本。
打印“伪终端”行是ssh因为当命令行上没有提供要执行的命令时,它默认尝试分配 TTY。您可以通过在 ssh 命令中添加“-T”来避免该消息:
sshpass -p password ssh -T root@$line
Run Code Online (Sandbox Code Playgroud)
“警告:无法访问 tty”行来自远程系统上的 shell。csh并将tcsh在某些情况下打印该消息。它可能是由.cshrc远程系统上的文件或类似文件中的某些内容触发的,试图访问某些需要 TTY 的功能。
使用以下代码,
#!/bin/bash
#input server names line by line in server.txt
cat server.txt | while read line
do
sshpass -p password ssh root@$line 'hostname;uname -r'
done
Run Code Online (Sandbox Code Playgroud)