期望脚本未通过密码?

时间:2019-03-04 21:03:34

标签: expect ubuntu-18.04

新手在这里。我的目标是使Expect脚本登录到Ubuntu 18.04服务器并运行两个命令(lsb_release -a和ip addr),并最终将输出/结果传递到文件中。现在,我很乐意让这两个命令成功运行。该如何解决?

#!/usr/bin/expect 
set timeout 60 
spawn ssh admin@192.168.1.12
expect " admin@192.168.1.12's password: " 
send " admin\r" 
expect " admin@server1:~$ " 
send " \r" 
expect " admin@server1:~$ "
send " lsb_release -a "
expect " admin@server1:~$ " 

错误:我收到密码提示,但脚本未传递密码(??)

admin@server1:~$ expect test.exp
spawn ssh admin@192.168.1.12
admin@192.168.1.12's password:

使用cli中的“ ssh -l”进行正常响应/输出。

admin@server1:~$ ssh -l admin 192.168.1.12
admin@192.168.1.12's password:
Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-45-generic x86_64)

... misc output here

*** System restart required ***
Last login: Mon Mar  4 14:40:27 2019 from 192.168.1.10
admin@server1:~$

0 个答案:

没有答案