shell中嵌套执行expect命令实例(利用expect实现自动登录)
expect是
#!/bin/bash
passwd='123456'
/usr/bin/expect <<EOF
set time 30
spawn ssh root@192.168.76.10
expect {
"*yes/no" { send "yes\r"; exp_continue}
"*password:" {send "$passwd\r"}
}
expect "*#"
send "cd /tmp\r"
expect "*#"
send "echo 222 > 2.txt \r"
expect "*#"
send "df -h \r"
expect "*#"
send "free -m \r"
expect "*#"
send "ps -ef | grep httpd \r"
expect "*#"
send "quit\r"
interact
expect eof
EOF