#!/usr/bin/expect
set timeout 5
spawn ssh root@192.168.1.234
expect "*password*"
send "mypassword\r"
expect "*#"
send "cd /home/bob\r"
interact
send:用于向进程发送字符串
expect:从进程接收字符串
spawn:启动新的进程
interact:允许用户交互
#!/usr/bin/expect
set timeout 5
spawn ssh root@192.168.1.234
expect "*password*"
send "mypassword\r"
expect "*#"
send "cd /home/bob\r"
interact
send:用于向进程发送字符串
expect:从进程接收字符串
spawn:启动新的进程
interact:允许用户交互
转载于:https://my.oschina.net/bobwei/blog/3009468