[TOC]
ssh tools:Termius
Virtual Machine:vmware 14 Markdown:印象笔记 & Typora
- Enter the terminal
cd /etc/sysconfig/network-scripts
- Vi opens the corresponding network card configuration file. Centos defaults to ens33 and most other systems to enth0
vi ifcfg-ens33
-
Change ONBOOT=no to ONBOOT=yes Wq save
-
Restart the system, you will find that the network card has been booted with boot
-
Perform
fdisk -l
-
fdisk /dev/sdb
Format new hard disk -
Enter m to see help
-
Enter n to create a new partition, p to create a new primary partition, and 1 (primary partition number) to start and end the disk partition respectively.
-
Enter w to save the partition
-
```Fdisk -l
-
Input
MKFS. Corruption
-
Edit /etc/fstab and add at the bottom:
/ dev/sdb1 / app corruption defaults 0 0
Make the disk boot mount to the /app directory
vim /etc/fstab
The marked places are the places that need to be added. This means that the disk quota limit is applied to the root directory. Of course, it can also be added to other lines, which means that the disk quota limit is applied to other directories.
df -h
mount -o remount /app
mount | grep quota
yum install quota
quotacheck -cugm /dev/sdb1
ll / | grep quota
quotaon /dev/sdb1
mkdir thenewuser #记得更改文件权限
cp .bash_logout .bash_profil .bashrc /app/data/thenewuser
useradd -m -d /app/data/thenewuser thenewuser
edquota -u thenewuser
dd if=/dev/zero of=/app/data/file1 bs=1M count=450 #未超上限,无报错
dd if=/dev/zero of=/app/data/file2 bs=1M count=450 #报错
repquota /dev/sdb1
!/bin/bash
#userlist=cat /etc/passwd | awk 'BEGIN {FS=":"}{print $1}'
TEXT1=`cat "/etc/passwd"`
DATE=`date "+%Y-%m-%d_%H-%M"`
echo $DATE
USERNUMBER=`wc -l /etc/passwd|cut -d' ' -f1`
echo $USERNUMBER
USERALLLIST=`echo "$TEXT1" | awk 'BEGIN {FS=":"}{print $1}'`
echo $USERALLLIST
echo "********************************************************************************************************"
for((i=1;i<=$USERNUMBER;i++));do
echo "这是第 $i 个用户";
FORUSER=`cut -d: -f1 /etc/passwd | head -$i | tail -1`
echo $FORUSER
#CHECKFULLUSER=`repquota /dev/sdb1 | grep $FORUSER | tr -s ' ' |cut -d ' ' -f1`
CHECKFULLUSED=`repquota /dev/sdb1 | grep $FORUSER | tr -s ' ' |cut -d ' ' -f3`
CHECKFULLUSED=${CHECKFULLUSED:=0} #若 num 为空或未设置时,则 num 设为值 0
#echo $CHECKFULLUSER
echo $CHECKFULLUSED
if [ $CHECKFULLUSED -eq 500000 ]
then
echo "over used"
mkdir overuseddata-$FORUSER
mv ./overuseddata-$FORUSER /app/overuseddata
mv /app/data/$FORUSER/* /app/overuseddata/overuseddata-$FORUSER #移动所有滥用文件到overuseddata(不包括隐藏的配置文件)
tar -czvf $FORUSER-$DATE.tar.gz /app/overuseddata/overuseddata-$FORUSER
mv /app/$FORUSER-$DATE.tar.gz /app/overuseddata
rm -Rf /app/overuseddata/overuseddata-$FORUSER
echo "文件已移动"
elif [ $CHECKFULLUSED -gt 500000 ]
then
echo "over used"
mkdir overuseddata-$FORUSER
mv ./overuseddata-$FORUSER /app/overuseddata
mv /app/data/$FORUSER/* /app/overuseddata/overuseddata-$FORUSER #移动所有滥用文件到overuseddata(不包括隐藏的配置文件)
tar -czvf $FORUSER-$DATE.tar.gz /app/overuseddata/overuseddata-$FORUSER
mv /app/$FORUSER-$DATE.tar.gz /app/overuseddata
rm -Rf /app/overuseddata/overuseddata-$FORUSER
echo "文件已移动"
else
echo "used well"
fi
done;