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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM