sftp connection error checking
Posted on 2014-12-08
I would like to add a if else statement to this script to send an email alert if it cannot connect to the sftp server,
sftp firstname.lastname@example.org <<EOF
#if success continue on, else fail and email administrator
#a succesful connection appears below and is not part of the script...
SSH Server supporting SFTP and SCP
Connected to 192.168.100.100.
#next the script proceeds with uploading data...
!pwd >> /var/log/sftplog/sftp_$(date '+%d').log
!ls >> /var/log/sftplog/sftp_$(date '+%d').log
!mv /directory1/*.xml /directory1/archive/
When the script fails, its usually because either the sftp server it connects to is not accepting connections, or the network port shuts down at the firewall.
I would like for the script to have an if/else statment. if success, continue on processing the reminder of the script.
else fail, and mail an alert SFTP is down!