summaryrefslogtreecommitdiffstats
path: root/clean-logs.sh
blob: 0ea4956b5cff4245d3789c2c67dae09b4e75df9a (plain)
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
#!/bin/bash

# clean traditional logs etc.
find /var/log/ -type f -name "*.gz" -exec rm -f {} \;
find /var/log/ -type f -name "*.1" -exec rm -f {} \;
find /var/log/ -type f -name "*.old" -exec rm -f {} \;

# clean systemd's journal
if [[ -d /var/log/journal ]]; then
    systemctl stop systemd-journald
    journal_dirs=$(find /var/log/journal/ -maxdepth 1 -type d -name "a*")
    for j in $journal_dirs; do
        echo "removing ${j}"
        rm -rf $j
    done
    systemctl start systemd-journald
fi

# clean atop logs
if [[ -d /var/log/atop ]]; then
    systemctl stop atop
    rm -f /var/log/atop/*
    systemctl start atop
fi

# clean samba logs
if [[ -d /var/log/samba ]]; then
    rm -rf /var/log/samba/*
fi

# at last truncate all *.log
find /var/log/ -name "*.log" -exec truncate -s 0 {} \;

exit 0