shell中嵌套执行expect命令实例(利用expect实现自动登录)

expect是

#!/bin/bash
passwd='123456'
/usr/bin/expect <<EOF
set time 30
spawn ssh [email protected]
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

猜你喜欢

转载自www.cnblogs.com/mmdln/p/8963757.html