Linux下利用expect实现自动交互
首先要安装tcl,expect
下面是Linux下ssh自动交互的例子:
#!/usr/bin/expect -f
spawn ssh username@hostname
expect "*?assword:*"
send "11111\r"
expect "*>"
send "ls\r"
expect "*>"
send "exit\r"
interact
例子中的username@hostname为远程用户名和主机名
#!/usr/bin/expect -fset pasword "123456"set myPassword "710652627keke"spawn ssh-add /home/zhangjun/.ssh/id_dsa_112expect{"*passphrase" {send "$pasword\r"}}spawn ssh-add /home/zhangjun/.ssh/id_dsa.106expect{"*passphrase" {send "$myPassword\r"}}interact