#!/bin/bashset +x## global constantsPROGNAME=$(basename $0)VERSION="1.0"## global variablesMY_DISKS="SATA_WDC_WD800AAJS-0_WD-WCAS25853716SATA_Hitachi_HDP7250_GEA534RF2A2W5A"MY_PATH="/dev/disk/by-id/"## functions used in this scripterror_exit() { echo "you're not root, bailing out" && exit 1; }## check permissions/executing user id[[ ! $EUID -eq 0 ]] && error_exit## main program starts here## for every disk in MY_DISKS, do followingfor i in $MY_DISKS; do ## check if device is present# if [ "$(ls /dev/disk/by-id/ | grep $i)" != "" ]; then if [ -L "$MY_PATH"*"$i" -a -b "$MY_PATH"*"$i" ]; then echo "Disk $i is present." ## unmount all mounted partitions for foo in "$MY_PATH"*"$i"-* ; do ## find out the sdXY name of the partition, #=> MY_HELPER0=sdXY MY_HELPER0="$(readlink -f "$foo")" [[ "$(grep $MY_HELPER0 /proc/mounts 2>/dev/null)" ]] && umount "$MY_HELPER0" || : done sync && echo "all partitions unmounted and synced, you may safely remove your device now" echo "press any key to continue when done to re-scan the SCSI Bus" read CONTINUE_KEY# trigger a re-scan of the bus echo "SCSI Bus re-scan now." echo "0 0 0" > /sys/class/scsi_host/host4/scan else echo -e "Drive $i not present. \nPlease insert drive $i and hit any key to continue" read CONTINUE_KEY echo "SCSI Bus re-scan now." echo "0 0 0" > /sys/class/scsi_host/host4/scan for foo in "$MY_PATH"*"$i"-part* ; do IFS=_ read -r _ MY_VENDOR _ <<< "$foo" MY_PARTNR="${foo##*-}" MY_HELPER1="$(readlink -f "$foo")" [[ ! -d /mnt/"$MY_VENDOR"-"$MY_PARTNR" ]] && mkdir -p /mnt/"$MY_VENDOR"-"$MY_PARTNR" mount "$MY_HELPER1" /mnt/"$MY_VENDOR"-"$MY_PARTNR" done fidone