title: Bash Script - Check mounted devices
body: <p>What I'm trying to do -
  In the end, I want a script that checks for 3 devices, an SD card, Backup1 &amp; Backup2. They've all been set to auto-mount at their respective mountpoints. The script should check for SD card first, if this fails, then a warning should be sent, and nothing more. If SD is okay, but only one backup is mounted, then ask for confirmation to go ahead with rsync to mounted backup. If all devices are mounted, then rsync from SD card to both backups.</p>
  
  <p>Currently I'm just trying to get the device check nailed, using echo commands. Here's what I have (after multiple attempts) - </p>
  
  <pre><code>if ! mount | grep /media/card &gt;/dev/null
  then
      echo "ERROR: SD card not mounted, aborting"
  else
      if ! mount | grep /media/backup &gt;/dev/null
          then
              if ! mount | grep /media/backup2 &gt;/dev/null
              then
                  echo "ERROR: No backup devices"
              else
                  echo "CAUTION: Backup_2 missing, Backup_1 OKAY"
              fi
      else
          if ! mount | grep /media/backup2 /dev/null
          then
              echo "CAUTION: Backup_1 missing, Backup_2 OKAY"
          else
              echo "SUCCESS: All devices OKAY"
          fi
      fi
  fi
  </code></pre>
  
  <p>Which isn't working. I'm getting confused by all the nested 'if's and surely there's a simpler way? Perhaps something that checks each device independently, then returns values that equate to the various combinations (0=no devices, 1=sd only, 2=sd &amp; backup1, 3=sd &amp; backup 2, 4 = all okay) which then is read and decides next part of script to run? If not, where has this way gone wrong?</p>
  
  <p>Any help is appreciated </p>