My goal is to rename a file on an sftp server using expect, AND if the rename fails, to exit expect returning a status code of 1
My expect script works fine - it successfully renames.
I cannot work out how to exit with a status code if the rename fails.
ubuntu@ip-10-0-0-138:~$> cat expect_script.txt
spawn sftp -o "StrictHostKeyChecking no" ubuntu@nginx.localvpc
expect "password:"
send "somesupersecretpassword\n"
expect "sftp>"
send "rename /var/www/static/tmp-93121715.mp4 /var/www/static/91329728.mp4\n"
expect "sftp>"
send "rename /var/www/static/91329728.mp4 /var/www/static/tmp-93121715.mp4\n"
expect "sftp>"
send "bye\n"
expect "#"
exit
Here is the output when I run my script:
ubuntu@ip-10-0-0-138:~$> expect -f expect_script.txt
spawn sftp -o StrictHostKeyChecking no ubuntu@nginx.localvpc
ubuntu@nginx.localvpc's password:
Connected to nginx.localvpc.
sftp> rename /var/www/static/tmp-93121715.mp4 /var/www/static/91329728.mp4
rename /var/www/static/tmp-93121715.mp4 /var/www/static/91329728.mp4
sftp> rename /var/www/static/91329728.mp4 /var/www/static/tmp-93121715.mp4
rename /var/www/static/91329728.mp4 /var/www/static/tmp-93121715.mp4
sftp> bye
bye
ubuntu@ip-10-0-0-138:~$>
Can anyone please suggest what I can do to exit with return code zero if the rename fails?
Bonus question... what's the correct way to exit at the end of my expect script? Is it one of these?
exit
close
expect eof
thanks!