#!/bin/bash
# chkconfig: 345 85 15
# description: Will automatically mount a removable device if present.
#
#: Script Name	: custom_mount.sh
#: Version	: 1.0.3
#: Author	: Matthew Mattoon - http://blog.allanglesit.com
#: Date Created	: August 15, 2012
#: Date Updated	: February 20, 2013
#: Description	: Automount Removable Logical Volumes Script.
#: Examples	: custom_mount.sh ACTION
#: 		: custom_mount.sh start

vgtest="vg_data"
vgs=`vgs | grep $vgtest`

case "$1" in 
 start)
  if [ -n "$vgs" ]
   then
    echo "Logical Volume Group: $vgtest present."
    mounts=`cat /etc/fstab | grep $vgtest | grep noauto | tr '\t' ' ' | tr -s ' ' | cut -d " " -f 2`
    for mount in $mounts
     do
      if [ -z "`mount | grep $mount`" ]
       then
        echo "Mounting $mount file system..."
	mount $mount
       else
        echo "File system $mount is already mounted..."
       fi
     done
   else
    echo "Logical Volume Group: $vgtest not present."
    exit 1
   fi
  ;;
 stop)
  if [ -n "$vgs" ]
   then
    echo "Logical Volume Group: $vgtest present."
    mounts=`cat /etc/fstab | grep $vgtest | grep noauto | tr '\t' ' ' | tr -s ' ' | cut -d " " -f 2`
    for mount in $mounts
     do
      if [ -n "`mount | grep $mount`" ]
       then
        echo "Unmounting $mount file system..."
        umount $mount
       else
        echo "File system $mount is already unmounted..."
      fi
     done
   else
    echo "Logical Volume Group: $vgtest not present."
    exit 1
  fi
  ;;
 *)
  echo "Usage: $0 start"
  exit 1
esac

