• 新增磁盘自动挂载脚本


    #!/bin/bash
    #2020-11-26
    #Auto scan and mount useless disk 
    #Version: 1.0
    
    function SCAN {
    	echo -e "33[44;37mScaning...33[0m"
    	sleep 1
    	> /tmp/mount.log
    	ALL_DISK=`fdisk -l | grep -Ev "mapper|root|swap|docker" |grep ^"Disk /"|cut -d ' ' -f2 |cut -d: -f1`
    	for i in ${ALL_DISK}
    	do
    		df -Th | grep ${i} &> /dev/null
    		if [ $? -eq 0 ];then
    			echo -e "Found Disk: ${i}  - 33[31mUsed33[0m" | tee -a /tmp/mount.log
    		else
    			echo -e "Found Disk: ${i}  - 33[32mUseless33[0m" | tee -a /tmp/mount.log
    		fi
    	done
    	Used_Disk=`cat /tmp/mount.log | grep Used | cut -d ' ' -f3`
    	Useless_Disk=`cat /tmp/mount.log | grep Useless | cut -d ' ' -f3`
    }
    function PART {
    	for i in ${Useless_Disk}
    	do
    		echo -e "33[36mFormating ${i}....33]0m"
    	sleep 1
    FDISK=`which fdisk`
    ${FDISK} ${i} &> /dev/null <<EOF
    n
    p
    1
    
    
    wq
    EOF
    	echo -e "33[32mDone33[0m"
    	done
    }
    function MKFS {
    	for i in ${Useless_Disk}
    	do
    		echo -e "33[36mMkfs ${i}....33]0m"
    		mkfs.ext4 ${i}1 &> /dev/null
    		echo -e "33[32mDone33[0m"
    		sleep 1
    	done
    }
    function MOUNT {
    	for i in ${Useless_Disk}
    	do
    		if [ ! -d /data ];then
    			mkdir /data
    			UUID_NUM=`blkid | grep "${i}1" | cut -d ' ' -f2`
    			echo "${UUID_NUM} /data	ext4	defaults 0 0" >> /etc/fstab
    			mount -a
    			[ $? -eq 0 ] && echo "${i} Mount Finished." 
    		else
    			read -p "/data in uesd,Input new mount point:" NEW_POINT
    			if [ -d ${NEW_POINT} ];then
    				read -p "${NEW_POINT} in uesd,Input new mount point again:" NEW_POINT
    				mkdir ${NEW_POINT}
    				UUID_NUM=`blkid | grep "${i}1" | cut -d ' ' -f2`
    				echo "${UUID_NUM} ${NEW_POINT}	ext4	defaults 0 0" >> /etc/fstab
    				mount -a
    				[ $? -eq 0 ] && echo "${i} Mount Finished." 
    			else
    				mkdir ${NEW_POINT}
    				UUID_NUM=`blkid | grep "${i}1" | cut -d ' ' -f2`
    				echo "${UUID_NUM} ${NEW_POINT}	ext4	defaults 0 0" >> /etc/fstab
    				mount -a
    				[ $? -eq 0 ] && echo "${i} Mount Finished." 
    			fi
    		fi
    	done
    }
    function MAIN {
    	SCAN
    	if [ -z "${Useless_Disk}" ];then
    		echo -e "33[31mNot Fount Useless Disk.Exited...33[0m" && exit 2
    	fi
    	PART
    	MKFS
    	MOUNT
    	rm -fr /tmp/mount.log
    }
    MAIN
    
    
  • 相关阅读:
    zabbix--完整安装攻略
    python--8大排序(原理+代码)
    python--二分法查找
    celery生产者-消费者
    python--基础知识点梳理(之数据结构)
    mysql--事务详解
    python--基础知识点梳理(三)深浅拷贝、进线协程、os和sys、垃圾回收机制、读文件的三种方式
    python--基础知识点梳理(二)面向对象
    python--基础知识点梳理(一)数据类型、迭代生成装饰器、函数
    java 集合
  • 原文地址:https://www.cnblogs.com/pansn/p/14061035.html
Copyright © 2020-2023  润新知