分区脚本 本文共有2474个字,关键词: ``` #!/bin/bash #分区脚本 #Auther:stone #列出系统上挂载的所有硬盘 echo -e "\033[31m`fdisk -l |grep '^Disk /dev/[sh]d[a-z]'`\033[0m" #统计已挂载硬盘数量 c=`fdisk -l 2>/dev/null |grep '^Disk /dev/[sh]d[a-z]' |wc -l` echo `fdisk -l |grep '^Disk /dev/[sh]d[a-z]' |cut -d ' ' -f 2 |cut -d : -f 1` >/tmp/list.txt #模块化减少代码 function change() { read -p "input a hard disk number:" hdnum number=`echo $hdnum |sed -r 's/[0-9]+//g'` if [[ $hdnum -gt $c ]] || [[ $hdnum -lt 1 ]] || [[ $number ]]; then echo -e "\033[31mplease try again(0-3).\033[0m"; continue fi hdw=`cat /tmp/list.txt |cut -d ' ' -f $hdnum` echo $hdw return } while :; do cat << EOF ############format sctipt############ ## a choice hard disk ## ## d delete hard disk parttion ## ## quit quit the script ## ##################################### EOF read -p "input your choice:" optiona case $optiona in a|A) for i in `seq 1 $c`; do echo -e "\033[32mThis is $i Hard Disk: `cat /tmp/list.txt |cut -d ' ' -f $i`\033[0m" done while :; do change read -p "you date will lose,sure to continue?(y|Y)" choose1 [ $choose1 != "y" ] || [ $choose1 != "Y" ] && echo -e "\033[32myou not change $hdw\033[0m"; break echo ' n p 1 +1G n p 2 +1G n p 3 +2G t 3 82 w' |fdisk $hdw &>/dev/null fdisk -l $hdw exit 0 done ;; d) for i in `seq 1 $c`; do echo -e "\033[32mThis is $i Hard Disk: `cat /tmp/list.txt |cut -d ' ' -f $i`\033[0m" done while :; do change echo -e "\033[310mare you sure clean the $hdw(y|n):" read choose [ $choose == "y" ] || [ $choose == "Y" ] && dd if=/dev/zero of=$hdw bs=512 count=1 echo -e "\033[32myou not clean the $hdw\033[0m" break done ;; q|quit) exit 0 ;; *) echo -e "\033[31mKnow option,please try again.\033[0m" ;; esac done ``` 「一键投喂 软糖/蛋糕/布丁/牛奶/冰阔乐!」 赞赏 × 几人行 (๑>ڡ<)☆谢谢老板~ 2元 5元 10元 50元 100元 任意金额 2元 使用微信扫描二维码完成支付 版权声明:本文为作者原创,如需转载须联系作者本人同意,未经作者本人同意不得擅自转载。 shell脚本 2017-03-07 评论 1670 次浏览