工作中涉及磁盘相关问题处理汇总

日志处理
找出大于某GB的文件,并清空
du -csh /export/Logs/*|grep -vE "M|total"|sed 's/G//'|awk '$1>10 {print $2}'
echo > `du -csh /export/Logs/*|grep -vE 'M|total'|sed 's/G//'|awk '$1>30 {print$2}'`

日志占用空间统计
[1018]# ansible -i iplist -o  all -m shell -a 'cd /export/Logs/;du -csh *|grep total'     

日志删除
[1018]# cd /export/Logs/;for i in {6..20};do \rm -rf  bj_ngnix.log.$i;done  

磁盘使用空间统计
[1018]# cat G.sh
Used:df -h|grep data|awk '{print $3}'|grep G|sed "s/G//"|xargs|sed 's/\s/+/g'|bc
Size:df -h|grep data|awk '{print $2}'|grep T|sed "s/T//"|xargs|sed 's/\s/+/g'|bc
[1018]# cat T.sh
df -h|grep data|awk '{print $3}'|grep T|sed "s/T//"|xargs|sed 's/\s/+/g'|bc
df -h|grep data|awk '{print $2}'|grep T|sed "s/T//"|xargs|sed 's/\s/+/g'|bc 

[1018]# ansible -i 2592 all -o  -m script -a "T.sh"  > 2592.txt
[1018]# ansible -i 407 all -o  -m script -a "G.sh"  > testG.txt 

服务器磁盘使用百分比统计
[1018]# df -h|grep data|awk '{print $5}'|sed "s/%//"|xargs|sed 's/\s/+/g'|bc;df -h|grep data|wc -l 

服务器磁盘总空间容量计算
[1018]# df -h|grep data|awk '{print $2}'|sed "s/T//"|xargs|sed 's/\s/+/g'|bc;

已删除的文件占用磁盘空间不释放问题处理
[1018]# for i in `lsof /export/|grep deleted|awk '{print $2}'|sort -nr|uniq`;do cd /proc/$i/fd/;pwd;for j in `lsof /export|grep deleted|awk '{print $9}'`;do /usr/bin/ls -l|grep $j|grep deleted|awk '{print $9}';for x in `/usr/bin/ls -l|grep $j|grep deleted|awk '{print $9}'`;do :>$x;done;done;done