Tcl期望保持SSH Spawn开放 [英] Tcl Expect Keep SSH Spawn open
问题描述
我想打开一个生成的SSH连接,然后(在循环中)向MySQL服务器查询新用户,并且如果找到新用户,则应通过Expect向该SSH连接发送命令.
I want to open a spawn SSH connection and then query a MySQL Server for new users (in a loop), and if a new user is found a command should be sent to this SSH Connection via Expect.
我不知道这是否可行,直到现在,当我在MySQL查询之后尝试发送"命令时,我总是杀死ssh.exe.
I don't know if this is possible, up until now i allways kill ssh.exe when i try the "send" command after the MySQL Query.
我希望SSH处于打开状态,因为用Expect登录需要10秒钟(主机运行缓慢),我也不希望每次创建用户时都暂停.
I want the SSH to be open because it takes 10 seconds to login with Expect (Host ist slow) and i don't want that pause everytime a create a user.
我该怎么做?
我在做什么:
...
set db [::mysql::connect -host 127.0.0.1 -user root -password **** -db test]
spawn ssh admin@192.168.1.2
expect {
timeout { send_user "\nFalscher SSH User admin!\n"; exit 1 }
"User:"
}
send "admin\r"
expect {
timeout { send_user "\nFalscher SSH User admin!\n"; exit 1 }
"Password:"
}
send "******\r"
set x = 1
while {$x>0} {
set query [::mysql::query $db {SELECT username, passwort FROM users WHERE erstellt='0'}]
while {[set row [::mysql::fetch $query]]!=""} {
set username [lindex $row 0]
set passwort [lindex $row 1]
send "create user...;\r"
}
::mysql::endquery $query
after 2000
}
推荐答案
我通过将期望输出保存到文件中来解决了这个问题. 在后台启动后,ssh想验证我的ssl指纹. 接受之后,它运行良好.
I solved this by saving the expect output into a file. After starting in the background, ssh wanted to verify my ssl fingerprint. After accepting that, it worked fine.
这篇关于Tcl期望保持SSH Spawn开放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!