#!/usr/bin/expect -f
set user root
set host 192.168.0.1
set password 123456
spawn ssh $user@$host
expect "*password:"
send "$password\r"
expect "]*"
send "ls \r"
interact
send:用于像进程发送字符串
expect:从进程接受字符串
spawn:启动新的进程
interact:允许用户交互
以上脚本的作用是:使用root用户登录到192.168.0.1这台机器,然后执行ls命令。