格式化和挂载硬盘shell

自己写一个批量格式化硬盘的shell脚本format.sh

#!/bin/bash
#Used to fomat 23 disks
#Write by junlee
#2010-04-27


PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
i=1
while [ $i -lt 24 ]
do
                j=`echo $i|awk '{printf "%c",97+$i}'`
                mkfs.xfs -f /dev/sd${j}1
                if [ "$?" = "0" ];then
                                echo "sd$j ____________________________________________was formated!!"
                fi
                let i+=1
done

批量挂载和卸载的的shell脚本mountdisk.sh

#!/bin/bash
#Use to mount 23 disks to /home[1-23]
#Write by junlee
#2010-04-27


PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

function_mount()
{
i=1
while [ $i -lt 24 ]
do
                j=`echo $i|awk '{printf "%c",97+$i}'`
                if [ -d /home$i ]
                then
                                echo "good!">/dev/null
                else
                                mkdir /home$i
                fi
                mount /dev/sd${j}1 /home$i
                let i+=1
done
}

function_umount()
{
i=1
while [ $i -lt 24 ]
do
                j=`echo $i|awk '{printf "%c",97+$i}'`
                umount /dev/sd${j}1
                let i+=1
done
}

if [ "$1" = "start" ];then
                echo "disks are mounting...."
                function_mount
                elif [ "$1" = "stop" ];then
                                echo "disks are umounting...."
                                function_umount
                                elif [ "$1" = "restart" ];then
                                                echo "disks are umounting...."
                                                function_umount
                                                sleep 5
                                                echo "disks are mounting...."
                                                function_mount
                else
                                printf "Usage:start|stop|restart"
fi

本文出自 “木子” 博客,谢绝转载!

你可能感兴趣的:(分区,shell,硬盘,格式化,休闲)