Reputation: 15
I wrote a bash code to send files to a sever computer from my remote laptop. I used 'scp' command and wrote it on a bash script to bypass entering a password every time I ran it.
expect <<EOF
spawn scp -P 1111 -o StrictHostKeyChecking=no -r /Users/Desktop/sync_mac [email protected]:/home/folder
expect "password:"
send "11111\r"
expect eof
EOF
However, the problem is when I ran the bash script on the terminal, it seemed like working well but suddenly failed sending files without any sign of warnings.(Especially for the case of sending a large number of files or a large size of file, it was okay for the case of a small number and a small size)
Thanks for your help
Upvotes: 1
Views: 985
Reputation: 20798
The default timeout for expect
is 10 seconds so expect eof
would wait for at most 10 seconds which may be not enough for many files as you mentioned.
To fix, you can set timeout -1
before expect eof
or just expect -timeout -1 eof
.
Upvotes: 1
Reputation:
I had to do this a while back, but for multiple servers, the list of which would change from night to night. I discovered sometimes scp would ask to add the host to your list of known hosts first, or other messages for which I had to code handling. That could be getting buried in your script.
This is an excerpt of what ultimately worked, if that helps:
expect -c "
spawn ssh-copy-id -i /x/home/$USER/.ssh/id_rsa.pub $USER@$HOST
expect {
\"password:\" {
send \"$PASS\n\"
expect {
\"expecting.\" { }
timeout {exit 1}
\"again.\" {exit 1}
}
}
\"yes/no)?\" {
send \"yes\n\"
expect \"password:\" {
send \"$PASS\n\"
expect {
\"expecting.\" { }
timeout {exit 1}
\"again.\" {exit 1}
}
}
}
}
Upvotes: 0