Tentativas sucessivas de montagem em casos de falha de montagem de compartilhamentos

De Wiki Hackstore

Em casos onde compartilhamentos windows ou samba demorem muito a montar, podem ocorrer falhas de montagem que caso fossem repetidas seriam realizadas com sucesso. Também são comuns estes erros em compartilhamentos NFS.


Script para montagem executado localmente (por ex: /etc/crontab)

#!/bin/bash

CHECK_CIFS_MOUNT=$(mount |grep cifs|grep 192.168.0.15| wc -l)
if [ "${CHECK_CIFS_MOUNT}" -eq 0 ]; then
        echo -e "CIFS desmontado. montando...\n" 
        mount.cifs //192.168.0.15/dados /mount --verbose -o "domain=hackstore,username=administrador,password=senhacabolosa"
        sleep 3
CHECK_CIFS_MOUNT=$(mount |grep cifs|grep 192.168.0.15| wc -l)
elif [ "${CHECK_CIFS_MOUNT}" -eq 0 ]; then
        echo -e "CIFS desmontado. montando...\n" 
        mount.cifs //192.168.0.15/dados /mount --verbose -o "domain=hackstore,username=administrador,password=senhacabolosa"
        sleep 3
CHECK_CIFS_MOUNT=$(mount |grep cifs|grep 192.168.0.15| wc -l)
elif [ "${CHECK_CIFS_MOUNT}" -eq 0 ]; then
        echo -e "CIFS desmontado. montando...\n" 
        mount.cifs //192.168.0.15/dados /mount --verbose -o "domain=hackstore,username=administrador,password=senhacabolosa"
        sleep 3
CHECK_CIFS_MOUNT=$(mount |grep cifs|grep 192.168.0.15| wc -l)
elif [ "${CHECK_CIFS_MOUNT}" -eq 0 ]; then
        echo -e "CIFS desmontado. montando...\n" 
        mount.cifs //192.168.0.15/dados /mount --verbose -o "domain=hackstore,username=administrador,password=senhacabolosa"
        sleep 3
CHECK_CIFS_MOUNT=$(mount |grep cifs|grep 192.168.0.15| wc -l)
elif [ "${CHECK_CIFS_MOUNT}" -eq 0 ]; then
        echo -e "CIFS desmontado. montando...\n" 
        mount.cifs //192.168.0.15/dados /mount --verbose -o "domain=hackstore,username=administrador,password=senhacabolosa"
        sleep 3
CHECK_CIFS_MOUNT=$(mount |grep cifs|grep 192.168.0.15| wc -l)
elif [ "${CHECK_CIFS_MOUNT}" -eq 0 ]; then
        echo -e "CIFS desmontado. montando...\n" 
        mount.cifs //192.168.0.15/dados /mount --verbose -o "domain=hackstore,username=administrador,password=senhacabolosa"
        sleep 3
CHECK_CIFS_MOUNT=$(mount |grep cifs|grep 192.168.0.15| wc -l)
elif [ "${CHECK_CIFS_MOUNT}" -eq 0 ]; then
        echo -e "CIFS desmontado. montando...\n" 
        mount.cifs //192.168.0.15/dados /mount --verbose -o "domain=hackstore,username=administrador,password=senhacabolosa"
        sleep 3
CHECK_CIFS_MOUNT=$(mount |grep cifs|grep 192.168.0.15| wc -l)
elif [ "${CHECK_CIFS_MOUNT}" -eq 0 ]; then
        echo -e "CIFS desmontado. montando...\n" 
        mount.cifs //192.168.0.15/dados /mount --verbose -o "domain=hackstore,username=administrador,password=senhacabolosa"
        sleep 3
CHECK_CIFS_MOUNT=$(mount |grep cifs|grep 192.168.0.15| wc -l)
elif [ "${CHECK_CIFS_MOUNT}" -eq 0 ]; then
        echo -e "CIFS desmontado. montando...\n" 
        exit 1
CHECK_CIFS_MOUNT=$(mount |grep cifs|grep 192.168.0.15| wc -l)
elif [ "${CHECK_CIFS_MOUNT}" -gt 0 ]; then
echo montado

fi     


Script para montagem executado remotamente (comandos executados via SSH)

#!/bin/bash
#set -x

ERRORLOG="/root/checkmount.log"
MNTDIR="/hd-ext"
REMOTE_CMD="ssh 192.168.100.254"
UUID_HD="119e95ad-4dcf-44a4-b34e-ee2a206b4288"

####################################################################################################################
# Desmontando HD externo

MOUNTED=$(${REMOTE_CMD} "mount|grep $(${REMOTE_CMD} "blkid |grep ${UUID_HD}|cut -d':'  -f1")|grep "${MNTDIR}"|wc -l")
if [ ${MOUNTED} -ne 0 ]; then
        ${REMOTE_CMD} 'umount /hd-ext/' > /dev/null
fi

####################################################################################################################
# Montando HD externo


MOUNTED=$(${REMOTE_CMD} "mount|grep $(${REMOTE_CMD} "blkid |grep ${UUID_HD}|cut -d':' -f1")|grep "${MNTDIR}"|wc -l")


if [ ${MOUNTED} -eq 0 ]; then
        echo -e "Montando o HD externo..."
        ${REMOTE_CMD} "mount UUID="lalala${UUID_HD}" ${MNTDIR}" 2> ${ERRORLOG}
        sleep 3

        MOUNTED2=$(${REMOTE_CMD} "mount|grep $(${REMOTE_CMD} "blkid |grep ${UUID_HD}|cut -d':'  -f1")|grep "${MNTDIR}"|wc -l")
        if [ ${MOUNTED2} -eq 0 ]; then
                echo -e "Montando o HD externo..."
                ${REMOTE_CMD} "mount UUID="lalala${UUID_HD}" ${MNTDIR}" 2> ${ERRORLOG}
                sleep 3

                MOUNTED3=$(${REMOTE_CMD} "mount|grep $(${REMOTE_CMD} "blkid |grep ${UUID_HD}|cut -d':'  -f1")|grep "${MNTDIR}"|wc -l")
                if [ ${MOUNTED3} -eq 0 ]; then
                        echo -e "Montando o HD externo..."
                        ${REMOTE_CMD} "mount UUID="${UUID_HD}" ${MNTDIR}" 2> ${ERRORLOG}
                        sleep 3

                        MOUNTED4=$(${REMOTE_CMD} "mount|grep $(${REMOTE_CMD} "blkid |grep ${UUID_HD}|cut -d':'  -f1")|grep "${MNTDIR}"|wc -l")
                        if [ ${MOUNTED4} -eq 0 ]; then
                                echo "erro de montagem, saindo...."
                                exit 1
                        else
                                echo "executa bkp"
                        fi
                fi
        fi
fi


####################################################################################################################
# Desmontando HD externo

MOUNTED=$(${REMOTE_CMD} "mount|grep $(${REMOTE_CMD} "blkid |grep ${UUID_HD}|cut -d':'  -f1")|grep "${MNTDIR}"|wc -l")
if [ ${MOUNTED} -ne 0 ]; then
        ${REMOTE_CMD} 'umount /hd-ext/' > /dev/null
fi


####################################################################################################################
# fim