#!/bin/bash
mkdir /my
fdisk /dev/sdb <<EOF
n
p
1
1
w
EOF
sleep 5
osdistrib=$(cat /etc/redhat-release |awk -F '.' '{print $1}' |awk '{print $3}')
if [ $osdistrib -eq 5 ];then
mkfs -t ext3 /dev/sdb1
else
mkfs -t ext4 /dev/sdb1
e2label /dev/sdb1 "/my"
echo 'LABEL=/my /my ext4 noatime,nodiratime,data=writeback 1 2' >> /etc/fstab
fi
mount -a
else
echo "This disk has partitioned!"
fi
#shel脚本格式化linux系统脚本
#查看sdb外挂目录是否已经格式化,没有格式化,将格式化。
count=`ls -l /dev/sdb* | wc -l`
if [ $sdb_count -eq 1 ];thenmkdir /my
fdisk /dev/sdb <<EOF
n
p
1
1
w
EOF
sleep 5
osdistrib=$(cat /etc/redhat-release |awk -F '.' '{print $1}' |awk '{print $3}')
if [ $osdistrib -eq 5 ];then
mkfs -t ext3 /dev/sdb1
e2label /dev/sdb1 "/my"
#相应目录写入到/etc/fstab表
else
mkfs -t ext4 /dev/sdb1
e2label /dev/sdb1 "/my"
echo 'LABEL=/my /my ext4 noatime,nodiratime,data=writeback 1 2' >> /etc/fstab
fi
mount -a
else
echo "This disk has partitioned!"
fi