自动创建分区的shell脚本
发布时间:2016-10-25 10:39:50 所属栏目:Linux 来源:网络整理
导读:题目:用shell脚本自动添加分区,已实现功能如下: 1.检查扩展分区是否,且是否可以添加,如果可以则把所有的剩余空间设置为扩展分区 2.当扩展分区存在,则输入
|
题目:用shell脚本自动添加分区,已实现功能如下: 1.检查扩展分区是否,且是否可以添加,如果可以则把所有的剩余空间设置为扩展分区 2.当扩展分区存在,则输入要添加的分区大小,仅接受大于1的正整数 代码如下:
#!/bin/bash
Hard='/dev/sda'
Exten=`fdisk -l $Hard|grep Extended`
Maxnum=`fdisk -l $Hard|grep -o "^/dev/sda[1-9]>"|tr -d [[:punct:]]|tr -d 'A-Za-z'|sort -n|tail -1
if [[ -z $Exten ]];then
if [[ $Maxnum -ge 4 ]];then
echo "Disk partitions error!..."
exit 1
elif [ $Maxnum -eq 1 -o $Maxnum -eq 2 ];then
# echo "1---3"
cat << EOF
e|E)use all free disk greate is Extended;
*)Quit;
EOF
Sdanum=$((Maxnum+1))
read Opt
case $Opt in
e|E)
fdisk $Hard &> /opt/fdisk.log <<EOF
n
e
$Sdanum
w
EOF
;;
*)
echo "None operating ,Exit"
exit 2
;;
esac
else
cat << EOF
e|E)use all free disk greate is Extended;
*)Quit;
EOF
read Opt
case $Opt in
e|E)
fdisk $Hard &> /opt/fdisk.log <<EOF
n
e
w
EOF
;;
*)
echo "None operating ,Exit"
exit 2
;;
esac
fi
else
echo 'Please input new partition size(MB),Only number.'
read Size
Pun=`echo "$Size"|grep "[[:punct:]]+"`
while [[ $Size -le 1 || -n $Pun ]]
do
echo "Wrong try again!"
Size=
read Size
Pun=`echo "$Size"|grep "[[:punct:]]+"`
done
answer=${Size:-50}
fdisk $Hard &> /opt/fdisk.log <<EOF
n
+${Size}M
w
EOF
fi
URL:http://www.bianceng.cn/OS/Linux/201410/45683.htm (编辑:佛山站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |

