So I am trying to catch specific errors whilst transferring files using LFTP, but the problem is, I am unable to catch them due to calling the <<EOF
to allow interfacing with the interactive shell.
The code I am using is as follows:
#Start backup procedure
lftp<<EOF
open ftps://$HOST || bye && #SEND MAIL CANNOT CONNECT TO SERVER (ERROR)
login $USER $PASSWORD || #SEND MAIL AUTH FAILURE (ERROR)
#Remove existing backups on FTP server
glob -a rm -r ./* || bye && #SEND MAIL FAILED (WARNING) TO REMOVE PREVIOUS BACKUPS
#Upload new backup to FTP server
lcd /var/opt/gitlab/backups
mput *.tar || bye && #SEND EMAIL (ERROR) FAILED TO UPLOAD FILES
bye
EOF
Obviously when bye is called the interactive session is closed, but nothing gets executed after the &&.
Anyone have any idea on how to do specific error catching like this?
您可以使用括号将命令分组:
open... || (shell send-mail; exit 1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.