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

shell script自动搭建简单的quota(磁盘配额)

2013-03-04 17:27 330 查看
#!/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

read -p "Please input a number of soft block [0]:" sb

read -p "Please input a number of hard block ,must be great than 0:" hb

read -p "Please input a number of soft inode [0]:" si

read -p "Please input a number of hard inode [0]:" hi

sb=0

si=0

hi=0

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

if [ $hb = "0" ] && [ -z $hb ]

then

echo "hard block must be great than 0"

echo "please use Usage:edquota -u user to create disk-quotas"

exit 77

fi

if [ $sb -gt $hb ]

then

tmp=${sb}

sb=${hb}

hb=${tmp}

fi

setquota -u $user ${sb} ${hb} ${si} ${hi} $mou

if [ $? -eq 0 ]

then

echo "create quota for $user"

echo "It's ok..."

else

echo "Please check $user is exist in your system !!!"

exit 77

fi

else

echo "please in put a right 'Mounted on' "

mv $temp $file

rm -rf $file.bak

#exit 0

fi

fi

本文出自 “无咎” 博客,请务必保留此出处http://perofu.blog.51cto.com/6061242/1144592
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: