磁盘根据UUID自动挂载

作品设计

作者:biner · 时间:2018-06-11 · 点击数:2564 · 评论:0

磁盘,U盘等根据UUID自动挂载到指定位置
diskautomount.sh

#!/bin/sh

CONFIG=$(cat /home/diskautomount/mount.conf)

old_IFS=$IFS   #保存旧的IFS
IFS=$'n'         #将IFS设为换行符

out=$(blkid);
for line in $out;do
    DEV_NAME=`echo $line|sed 's/(/dev/[0-9a-zA-Z].*):.*/1/'`
    UUID=`echo $line|sed 's//.* UUID="([0-9a-zA-Z-].*)" TYPE=.*/1/'`
    for linex in $CONFIG;do
        CONF_PATH=`echo  $linex|sed 's/(.*)=.*/1/'`
        CONF_UUID=`echo  $linex|sed 's/.*="(.*)"/1/'`
        
        if [ "$UUID" == "$CONF_UUID" ];then
            mount $DEV_NAME $CONF_PATH
             #echo "$UUID  = $CONF_UUID"
             #echo "$(echo  -n $UUID | md5sum) = $(echo  -n $CONF_UUID | md5sum )>>>>>>>>> $UUID=$CONF_UUID"
            echo "$DEV_NAME is mount at $CONF_PATH"
        #else
            # echo "$(echo  -n $UUID | md5sum) != $(echo  -n $CONF_UUID | md5sum )>>>>>>>>>$UUID!$CONF_UUID"
            
            #echo "$UUID  != $CONF_UUID"
        fi
    done
done
IFS=$old_IFS
mount.conf
/camera="1bf66fed-acba-4fca-9875-4a19a055a5dc"
添加到rc.loacl
#chmod +x diskautomount.sh
#./diskautomount.sh mount.conf

标签:
评论列表