#!/bin/bash function fdisk_fun() { fdisk $1 <<EOF n p 1 2048 w EOF mkfs.xfs $11 >>/dev/null 2>&1 } a=‘v‘ echo -ne "\033[32m Please confirm machine ,if is not ali,enter N|n.otherwise:\033[0m" read CHOICE if [ $CHOICE == ‘N‘ -o $CHOICE == ‘n‘ ] then a=‘s‘ fi if [ -f ./test.txt ] then rm -rf ./test.txt else touch ./test.txt fdisk -l |grep -o "^Disk /dev/$a[hd][a-z]" >>./test.txt fi n=1 for disk in `ls -al /dev|grep -o "$a[hd][a-z]"|uniq -c|gawk ‘{if( $1< 2) print $2}‘` do value=`grep $disk ./test.txt|wc -l` if [ $value == 1 ] then echo -e "\033[32m/dev/$disk can fdisk well\033[0m" read -p "Are you sure?(Y|y or N|n):" choice if [ $choice == ‘Y‘ -o $choice == ‘y‘ ] then if [ -d /data$n ] then mkdir /data$n fdisk_fun /dev/$disk ; mount /dev/$disk‘1‘ /data$n sed -i ‘$a /dev/‘$disk‘1 /data‘$n‘ xfs defaults,noatime,nodiratime 0 0‘ /etc/fstab let n+=1 fi else echo -e "\033[31mExitting\033[0m" exit 1 fi else echo -e "\033[31m$disk isn‘t a disk\033[0m" fi done
时间: 2024-11-03 20:44:53