Restic Output when not mounted?

Hi,
Currently running a script to do my restic backups daily which has been great, I have mounted my windows share on a debian machine that is running restic and mounted my NAS, i was wondering what possibility to put the output when it fails to get an email. Right now i get an email saying it was successfully, but when i check the email i know it was not successful because of the output of the file would there be a way to output the error below to the script?
This is the script
https://pastebin.com/Ap1pirk0

if i run the script manually when the nas is not mounted i get this

May 26 2018 16:45:12 -05: backup-script started
open repository
 Fatal: unable to open config file: Stat: stat /media/backupnas2/config: no such file or directory
Is there a repository at the following location?
/media/backupnas2
    Fatal: unable to open config file: Stat: stat /media/backupnas2/config: no such file or directory
 Is there a repository at the following location?
 /media/backupnas2
 Fatal: unable to open config file: Stat: stat /media/backupnas2/config: no such file or directory
 Is there a repository at the following location?
  /media/backupnas2
 using temporary cache in /tmp/restic-check-cache-197644745
 Fatal: unable to open config file: Stat: stat /media/backupnas2/config: no such file or directory
Is there a repository at the following location?
 /media/backupnas2

Which is good i just want to pipe that down

Thank you

Iā€™m not sure how you run the script exactly, but Iā€™m guessing that you only redirect the standard output to some kind of email program which mails it to you. Do you maybe also need to redirect the error output? Like, change backup_script.sh | mail to backup_script.sh 2>&1 | mail?

Another way would be to have the script check if the file /media/backupnas2/config exists. If not, thereā€™s no repo mounted thereā€¦

Thanks for the reply, that was a really good idea im still working on it ill post back if i get any luck

I created a script for every SMB Target that I want to backup that checks if the mount is there

Instead of ā€œecho failedā€ i will change this to send an email
``
if ! grep -q $RESTIC_BACKUP_FROM /proc/mounts ; then
if ! mount $RESTIC_BACKUP_FROM ; then
echo ā€œfailedā€
exit 1
fi
fi

/usr/bin/restic
``

1 Like

Thanks for the reply, i think i got it maybe something like this

#!/bin/sh
#Email Variables
 #sender="email@mydomain.com"
 #recipient="email@mydomain.com"
#company="companyname"

   #check if its mounted the NAS
  mount | grep "192.168.3.15" > Backups
 NAS=`cat Backups | sed '/^\s*$/d' | wc -l`
 if [ $NAS -eq 0 ]
  then
  echo -e "Subject: Backup Failed daily $company\n\nBackup Failed because the NAS  is not  mounted" | sendmail -f "$sender" "$recipient" -u
      exit 1;
     fi

Whats odd if you run it it works but if you put it as a cron job it wont work