Expect timeout processing

  shell

timeout

#!/bin/bash
/usr/bin/expect <<-EOF

set timeout 10000

spawn scp xixicat@10.12.191.128:/home/xixicat/demofile .
expect -exact "xixicat@10.12.191.128's password:"
send "demopwd\r"
expect "100%"
expect eof
EOF
echo "finish"

If timeout is not set or timeout is not long enough, the effect of spawn cannot be guaranteed. Due to network reasons, it is possible to timeout. send the password first, and then return the expected password.