gpt4 book ai didi

Bash - SSH 多个命令,它们之间有延迟

转载 作者:行者123 更新时间:2023-12-02 14:02:12 25 4
gpt4 key购买 nike

我正在尝试连接到路由器的子模块,在其上运行一些命令并将输出保存到文件中。我遇到的问题是子模块需要用户名和密码,如果将所有命令放在一个脚本中,则会在提示输入它们之前发送用户名/密码详细信息。有没有办法在命令之间设置延迟,或者在同一个 SSH session 下批量运行它们?

我使用了 EOF 方法,并将命令放在单独的文件中(首选):

ssh user@root > file.log << EOF
session slot 1 # command to connect to the subslot.
# a delay of about 3 sec would be required before the credentials are sent
slot_username
slot_password
command1
command2
command3
exit
exit
EOF

此外,第二个导出应该让我离开路由器,但它只是被忽略了。

最佳答案

我以前用命名管道做过这个。创建一个命名管道并将其输入发送到 ssh 命令。

mkfifo a=rw FOO
cat FOO | ssh user@root > file.log

然后,您可以从另一个脚本将命令写入 FOO:
echo username >> FOO
sleep 3
echo password >> FOO

但是......存在一个工具来完成你正在做的事情。它被称为 clogin .请参阅 https://linux.die.net/man/1/clogin 上的文档

关于Bash - SSH 多个命令,它们之间有延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40753455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com