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