simplycoding
simplycoding

Reputation: 2967

How do I catch an error from a Bash sftp connection?

How do I try an SFTP connection with a heredoc 3 times and catch an error? How do I restructure this to be proper? Error is being thrown on the first semicolon on the last line right before do

count=0; until sftp -o StrictHostKeyChecking=no -i key.pem [email protected] <<END
cd subfolder
END
; do ((count++)); [[ $count -eq 3 ]] && echo 'error' && break && exit 64; done;

Upvotes: 0

Views: 274

Answers (1)

Cyrus
Cyrus

Reputation: 88583

Try:

 until echo "cd subfolder" | sftp -o StrictHostKeyChecking=no -i key.pem [email protected]

Or take a look at sftp's option -b.

Upvotes: 1

Related Questions