shell脚本管理磁盘
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell脚本管理磁盘相关的知识,希望对你有一定的参考价值。
脚本功能:显示所有磁盘并选择,将被选择磁盘的分区全部革除,重新划分分区并格式化文件系统
#!/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脚本管理磁盘的主要内容,如果未能解决你的问题,请参考以下文章