shell log切割
apache log切割脚本
#!/bin/bash
logfile="/var/log/httpd/access_log"
pid=/run/httpd/httpd.pid
cp KaTeX parse error: Expected group after '_' at position 30: …og/httpd/access_̲(date -d “yesterday” +"%Y-%m-%d").log
kill -USR1 $(cat $pid)
#重新加载配置文件,重新生成log文件。达到平滑重启服务的目的
size=du -sh /var/log/httpd|awk '{print $1}'|awk -F 'K' '{print $1}'|awk -F 'M' '{print $1}'
echo $size
if [ $size -gt 1000 ]; then
find /var/log/httpd/ -type f -name access* -mtime +7 -exec rm -rf {} ;
else
echo “ok”
fi