-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclearlogs_docker.sh
More file actions
41 lines (30 loc) · 1.32 KB
/
clearlogs_docker.sh
File metadata and controls
41 lines (30 loc) · 1.32 KB
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
#!/bin/bash
echo "Stopping rsyslog service..."
systemctl stop rsyslog
echo "Truncating main log files..."
truncate -s 0 /var/log/syslog /var/log/btmp* /var/log/auth.log* /var/log/messages* 2>/dev/null
truncate -s 0 /var/log/*.log 2>/dev/null
truncate -s 0 /var/log/*.gz 2>/dev/null
truncate -s 0 /var/log/dpkg.log* /var/log/alternatives.log* /var/log/bootstrap.log /var/log/boot.log /var/log/cron* 2>/dev/null
truncate -s 0 /var/log/fontconfig.log /var/log/gpu-manager.log /var/log/odoocleanup.log /var/log/yum.log /var/log/vmware-* 2>/dev/null
echo "Removing old rotated and numbered logs..."
rm -f /var/log/*-??????? 2>/dev/null
rm -f /var/log/*.[0-9] 2>/dev/null
echo "Cleaning special log files..."
truncate -s 0 /var/log/wtmp /var/log/lastlog /var/log/tallylog /var/log/btmp 2>/dev/null
echo "Clearing sysstat and sa logs if exist..."
truncate -s 0 /var/log/sa/* 2>/dev/null
truncate -s 0 /var/log/sysstat/* 2>/dev/null
echo "Clearing all systemd journal logs..."
# Stop journal service temporarily
systemctl stop systemd-journald
# Remove all journal logs
rm -rf /var/log/journal/* 2>/dev/null
rm -rf /run/log/journal/* 2>/dev/null
# Restart journal service
systemctl start systemd-journald
echo "Starting rsyslog service..."
systemctl start rsyslog
echo "Log cleanup completed successfully."
# Show current /var/log size
du -sh /var/log