我想创建一个 bash 脚本,它将使用 ssh 登录到我网络中的所有 linux 服务器,并将“uptime”命令的输出收集到本地文件。这些本地服务器和远程服务器之间没有安装 key 对。所以我需要在脚本本身中提供密码(所有远程服务器的用户名和密码都相同)。我知道这不是一种安全的方法,但这只是为了学习目的。我看到“expect”命令可用于带密码的 ssh 登录,但混淆了如何将它与提供服务器状态的“uptime”命令一起使用。所以我的要求是
1. I have local server test1 which contains a text file 'server_status.txt'
2. I need a script in test1 that will try to login to all the remote servers (say 192.168.0.1 to 192.168.0.50) using the same username and password. It will execute the command 'uptime' once logged in to the remote servers and store the output to the local file 'server_status.txt'
最佳答案
REVOKE:将您的公钥粘贴到服务器的 /path2userthatshouldlogon/.ssh/authorized_keys
中并使用 ssh user@host commandtoexecute
远程运行您的命令
由于想在没有 key 的情况下建立连接。 更新:看看sshpass如果您确实需要密码,不推荐
关于linux - 没有 key 的 ssh 并使用 bash 脚本收集输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27941154/