I am trying to write a Bash script responsible for creating a folder on a remote server.
!/bin/bash -e echo "Creating remote folder." echo mkdir test_folder | sftp -oPort=22 192.168.0.11:/tmp if [[ $? != 0 ]]; then echo "Transfer failed!" exit 1 else echo "Transfer complete." fi echo $?
The output is:
Connected to 192.168.0.11. Changing to: /tmp sftp> mkdir test_folder Couldn't create directory: Failure Transfer complete. 0
So there return code is 0 but obviously there was an error.
How can I catch the remote error and set an appropriate return code in the script?