当前位置:网站首页>Some little records~

Some little records~

2022-04-23 14:22:00 Small ash pier

Some little records

1 The log content is cleaned regularly
# mkdir Test
# cd Test/
# touch a{1..10}.log
# ls
a10.log  a1.log  a2.log  a3.log  a4.log  a5.log  a6.log  a7.log  a8.log  a9.log
# for i in `ls ~/Test`;do echo "${i}">$i;done
 The above is the environment , In this similar environment , Cooperate with the task plan *.log journal 

# find /root/Test/ -name *.log |awk '{print "echo >" $1}' |bash
2 Log backup and cleanup 7 Day's diary
#!/bin/bash

#  This script is used to schedule task execution 
# crontab -l
# 59 23 * * * /bin/bash /kingdee/nginxLog/logrotate_nginx_log.sh > /dev/null 2>&1


nginx_log_path="/kingdee/nginxLog"

function logrotate_nginx_log(){
    

  if [ -d "${nginx_log_path}" ]; then

    cd ${nginx_log_path}

    cp error.log  cutlog/error-$(date -d "today" +"%Y%m%d").log
    echo > error.log

    cp access.log cutlog/access-$(date -d "today" +"%Y%m%d").log
    echo > access.log

    find ${nginx_log_path}/cutlog -mtime +7 -type  f -name "*.log" -exec  rm -f  {
    }  \;
  fi
}

logrotate_nginx_log
3 Display disk exceeds 80% Usage rate and corresponding directory
# df -h|awk '{if(NR != 1){split($5,a,"%");if(a[1]>0){print $5,$6}}}'|sort -t '%' -k1 -nr|egrep '[8-9][0-9]%|100%'
4 top in cpu Usage rate (100-id)
# top -b -n1 |fgrep 'Cpu(s):' |awk -F'id,' '{split($1,k,",");v=k[length(k)];sub(/%/,"",v);printf "%s\n",100-v;}'

版权声明
本文为[Small ash pier]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231409158352.html