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
#
#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
相关文章推荐
- shell script自动搭建简单的linux系统初始化脚本
- shell script自动搭建简单的lamp环境
- shell script自动搭建简单的dhcp服务器
- hell script自动搭建简单的iscsi服务器
- shell script自动搭建简单的nfs服务器
- linux学习shell----脚本3连发 ps ( 自动搭建本地YUM, 双色球摇号脚本, 点名脚本 )
- 简单使用shell 自动打包,发布项目 脚本
- linux c fork简单调用bin or shell script demo
- Linux 简单shell创建自己的守护进程,自动重启,纪录进程运行状态,日志切割压缩
- 简单的hibernate环境搭建、自动生成model/配置/hibernate.xml配置文件
- shell script自动搭建简单的pxe服务器
- shell script自动搭建简单的cacti监控
- shell简单编程——自动ping多台主机,返回结果
- shell脚本:自动搭建yum
- shell script自动搭建简单的mail服务器(postfix+dovecot)
- shell script自动搭建简单的yum
- shell script自动搭建简单的双机ssh认证
- shell centos 6.5 开发环境自动搭建
- shell script自动搭建简单的mysql主从(replication)
- oracle 自动生成 awr 报告的 简单 shell 脚本