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