I am using cron to run a script that connects to another server via sftp and uploads files. Once in a while, I will receive the error: Spawn-id-exp7-not-open while executing send \"ls\r\" and the script will stop executing (files will not be sent). However, most of the time, the script will run with no errors.
Below is my script I use to connect :
#!/bin/bash
HOST="removed.com:\API"
USER="user"
PASS="removed"
VAR=$(expect -c "
spawn sftp -o \"BatchMode no\" -b /var/www/prep/cmd -P 13266 $USER@$HOST
expect \"Password:\"
send \"$PASS\r\"
expect \"\\\\$\"
send \"ls\r\"
expect -re \"$USER.*\"
send \"exit\"
")
echo "==============="
echo "$VAR"
Below is the script that runs after I connect (cmd) :
put "/var/www/prep/1.xml"
put "/var/www/prep/2.xml"
I took a look at a similar question found at send: spawn id exp7 not open , but it has not helped me. Perhaps the connection ends before the cmd script can run?
Thanks for your help!