Nested execution of the expect command instance in the shell (using expect to achieve automatic login)

expect yes

#!/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

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325035452&siteId=291194637