-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogrotate.sh
49 lines (37 loc) · 1.09 KB
/
logrotate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Install logrotate if not already installed
if ! command -v logrotate &> /dev/null
then
apt-get install logrotate
fi
cat /dev/null > /var/log/daemon.log && cat /dev/null > /var/log/syslog
# Create configuration file
tee /etc/logrotate.d/daemon-syslog << EOF
/var/log/daemon.log /var/log/syslog {
size 5M
rotate 4
compress
delaycompress
missingok
notifempty
create 644 root adm
}
EOF
# Restart rsyslog service to apply changes
systemctl restart rsyslog
#chmod +x logrotate.sh
#./logrotate.sh
#设置要屏蔽的关键词
keywords=("systemd-logind: New session" "Created slice" "Starting Session" "Started Session" "Wi-Fi" "hostapd")
#将关键词转换为rsyslog配置格式
rules=""
for keyword in "${keywords[@]}"; do
rules+=":msg, contains, \"$keyword\" ~"$'\n'
done
#添加屏蔽规则到rsyslog配置文件
sed -i "/# Log anything (except mail) of level info or higher./a $rules daemon.*;mail.*;syslog;\
news.err;\
*.=debug;*.=info;\
*.=notice;*.=warn /dev/null" /etc/rsyslog.conf
#重启rsyslog服务
systemctl restart rsyslog