#!/bin/bash /usr/bin/expect <<-EOF set timeout 10000 spawn scp email@example.com:/home/xixicat/demofile . expect -exact "firstname.lastname@example.org'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.