首页 > 系统服务 > 详细

shell脚本管理磁盘

时间:2017-09-11 22:29:56      阅读:338      评论:0      收藏:0      [点我收藏+]
脚本功能:显示所有磁盘并选择,将被选择磁盘的分区全部革除,重新划分分区并格式化文件系统

#!/bin/bash

#显示所有磁盘并选择,将被选择磁盘的分区格式化,重新划分分区并格式化文件系统

 

echo -e "\e[1;34mYou have this disks:\e[0m"

 

fdisk -l 2> /dev/null | grep -o "^Disk /dev/[sv]d[a-z]"

 

echo -e "\e[1;31myour choice is:\nthis may destroy your data,you also can choose

 <quit>.\e[0m" 

read DISK

if [ $DISK == ‘quit‘ ];then

        echo 

        echo "quit."

        exit 2

else

        until fdisk -l 2> /dev/null | grep -o "^Disk /dev/[sv]d[a-z]" | grep "^D

isk $DISK$" &> /dev/null;do

                read -p  "Wrong option,Please choose again:" DISK

        done

 

        read -p "Dangeous! Are you sure continue:(yes/no) " CON

 

        if [ $CON == ‘no‘ ];then

                echo "quit."

                exit 3

                else

                        dd if=/dev/zero of=$DISK bs=512 count=1 &> /dev/null

                        sync

                        echo ‘

                        n

                        p

                        1

                        

                        +50M

                        n

                        p

                        2

                        

                        +50M

                        n

                        p

                        3

                

                        +50M 

                        w ‘ | fdisk $DISK &> /dev/null

                fi

fi

mke2fs -j ${DISK}1 &> /dev/null

v1=$?

if [ $v1 -eq 0 ];then

        echo "make ${DISK}1 succeed. "

fi

sleep 1

mke2fs -j ${DISK}2 &> /dev/null

v2=$?

if [ $v2 -eq 0 ];then

        echo "make ${DISK}2 succeed. "

fi

sleep 1

mke2fs -j ${DISK}3 &> /dev/null 

v3=$?

if [ $v3 -eq 0 ];then

        echo "make ${DISK}3 succeed. "

fi

 


本文出自 “11944248” 博客,请务必保留此出处http://11954248.blog.51cto.com/11944248/1964440

shell脚本管理磁盘

原文:http://11954248.blog.51cto.com/11944248/1964440

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!