Tcl Expect Keep SSH Spawn open

孤者浪人 提交于 2019-12-11 22:32:42

问题


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.

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.

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.

How can i do this?

What i am doing:

...
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
}

回答1:


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.



来源:https://stackoverflow.com/questions/27599806/tcl-expect-keep-ssh-spawn-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!