Frequently used scripts will be collected here for a long time and updated continuously. . . . .
Nginx access.log log analysis script
#!/bin/bash
BASE_PATH='/data/nginx/logs'
LOG_PATH=$(date -d yesterday +"%Y%m")
DAY=$(date -d yesterday +"%d")
SJ=`date -d "yesterday" "+%d/%b/%Y"`
date -d yesterday >> /home/shuju/shuju_$day.txt
#日UV
awk '{print $1}' $BASE_PATH/$LOG_PATH/access_$DAY.log|sort | uniq -c |wc -l >> /home/shuju/shuju_$DAY.txt
#日PV
awk '{print $1}' $BASE_PATH/$LOG_PATH/access_$DAY.log|wc -l >> /home/shuju/shuju_$DAY.txt
##峰值时间段
awk '{print $4}' $BASE_PATH/$LOG_PATH/access_$DAY.log| grep "$SJ" |cut -c 14-15|sort|uniq -c|sort -nr|head -n 24 >> /home/shuju/shuju_$DAY.txt
##访问频率前5的Url
awk '{print $7}' $BASE_PATH/$LOG_PATH/access_$DAY.log| sort | uniq -c | sort -nr | head -n 5 >> /home/shuju/shuju_$DAY.txt
Turn off firewall and selinux
#!/bin/bash
echo "关闭防火墙和selinux中...."
echo
systemctl stop firewalld && systemctl disable firewalld &> /dev/null && setenforce 0 && sed -i '/^SELINUX/s/enforcing/disabled/' /etc/selinux/config
if [ $? -eq 0 ];then
echo "防火墙和selinux已经成功关闭....."
else
echo "防火墙和selnux关闭失败,请手动关闭!!!"
fi