SoFunction
Updated on 2025-03-10

Nested execution of expect command instances in shell

I have always wanted to write the expected operation into the bash script, so I don’t have to write two more scripts to execute. After working on it for a while, I finally made some small achievements. Let me show you.

System:centos

1. Install expect first

Copy the codeThe code is as follows:

yum -y install expect

2. Script content:

Copy the codeThe code is as follows:

cat auto_svn.sh
#!/bin/bash
passwd='123456'
/usr/bin/expect <<-EOF
set time 30
spawn ssh -p18330 [email protected]
expect {
"*yes/no" { send "yes\r"; exp_continue }
"*password:" { send "$passwd\r" }
}
expect "*#"
send "cd /home/trunk\r"
expect "*#"
send "svn up\r"
expect "*#"
send "exit\r"
interact
expect eof
EOF

If you write this way, it will be much more convenient, and a script will be included.