forked from IBM/action-runner-image-pz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup.sh
More file actions
executable file
·42 lines (34 loc) · 1.06 KB
/
Copy pathcleanup.sh
File metadata and controls
executable file
·42 lines (34 loc) · 1.06 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
40
41
42
#!/bin/bash -e
################################################################################
## File: cleanup.sh
## Desc: Perform cleanup for RHEL
################################################################################
# before cleanup
before=$(df / -Pm | awk 'NR==2{print $4}')
# Clear the local repository of retrieved package files
yum clean all
rm -rf /var/cache/yum/*
rm -rf /tmp/*
rm -rf /root/.cache
# Rotate and vacuum journal logs if `journalctl` is available
if command -v journalctl; then
journalctl --rotate
journalctl --vacuum-time=1s
fi
# Delete all .gz and rotated files
find /var/log -type f -regex ".*\.gz$" -delete
find /var/log -type f -regex ".*\.[0-9]$" -delete
# Wipe log files
find /var/log/ -type f -exec cp /dev/null {} \;
# Remove mock binaries for yum/dnf
prefix=/usr/local/bin
for tool in yum dnf; do
rm -f $prefix/$tool
done
# after cleanup
after=$(df / -Pm | awk 'NR==2{print $4}')
# Display size
echo "Before: $before MB"
echo "After : $after MB"
# shellcheck disable=SC2004
echo "Delta : $(($after - $before)) MB"