您的位置:首页 > 运维架构 > Shell

搭建磁盘配额的shell script

2012-08-27 00:00 134 查看
#!/bin/bash
#
#Shell name:quota.sh
#
#Program:
# create disk-quotas for some users
#Author:pero
#Email: perofu.com@gmail.com
#History:
# 2012/07/18
#Usage:vi quota.sh ; :set ff=unix
#
#If you have any opinion please contact me

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

if [ $UID -ne 0 ]
then
echo "Run as root"
exit 1
fi

#check the soft do you have
soft=$(rpm -qa | grep quota)
file=fstab
temp=tmp.fs

if [ -z $soft ]
then
yum install quota -y &> //nulldev
echo "the soft of quota is install"
else
echo "the soft of quota was install"
fi

#config the /etc/fstab

read -p "please input a 'Mounted on' for check the partition :" mou
read -p "please input a user name to creating disk-quotas:" user

par=$(df -h | grep $mou | gawk '{print $1}')

cd /etc
cp -p $file $file.bak
mv $file $temp
n=$(grep -n $mou $temp | gawk 'BEGIN{FS=":"} {print $1}')

if [ -z $n ]
then
echo "$mou is not in you /etc/fstab file"
echo "please input a right 'Mounted on' "
else
sed ''$n's/defaults/defaults,usrquota,grpquota/' $temp > $file

if [ $? -eq 0 ]
then
rm -rf $temp
echo "writed config in /etc/fstab"
mount -o remount,usrquota,grpquota $mou

cd $mou

#quotacheck -ugcv $mou &> /dev/null
quotacheck -ugcva &> /dev/null

echo "please use Usage:edquota -u user to create disk-quotas"
echo "if you want to use some one who had created disk-quotas as a template to creating more users disk-quotas "
echo "please do this [./cpm_quota.sh]"

else
echo "please in put a right 'Mounted on' "
mv $temp $file
rm -rf $file.bak
#exit 0
fi
fi
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell script