Sending errors via mail

Hey guys.
I have created a script that mounts an external folder via sshfd, counts the number of files then do some delete and then counts the files again to get how many files have been deleted.

Then it sends the resault by mail.

My question is, how can i send via mail the errors on this script? I mean, if the password is incorrect or that it was unable to mount, or whatever.

This is the script.

paste.ubuntu.com /15759934/

thanks.

At the start of your script you can redirect all stderr to a file with the exec command and before exiting email that file to yourself...

exec 2>> error_file
.
.
.
mailx -s Errors your_email_address < error_file

Perfect.

Thanks.