scripts/Linux/zabbix/cleanup_disk.sh

44 lines
892 B
Bash
Raw Normal View History

2023-08-22 09:16:23 +02:00
#!/bin/bash
2023-08-22 15:56:34 +02:00
# prune container images
2023-08-22 09:16:23 +02:00
if [ -x "$(command -v docker)" ]; then
echo "Pruning using Docker"
sudo docker image prune -af
elif [ -x "$(command -v podman)" ]; then
echo "Pruning using Podman"
sudo podman image prune -af
else
echo "No container images to prune"
fi
2023-08-22 15:56:34 +02:00
# remove all disabled snaps
2023-08-22 09:16:23 +02:00
if [ -x "$(command -v snap)" ]; then
echo "Remove all deactivated snaps"
sudo snap list --all | \
awk '/disabled/{print $1, $3}' | \
while read snapname revision; do \
sudo snap remove "$snapname" --revision="$revision";
done
else
echo "No snaps found"
fi
2023-08-22 15:56:34 +02:00
# flush and rotate all logs
2023-08-22 09:16:23 +02:00
if [ -x "$(command -v journalctl)" ]; then
echo "Vacuuming logs using journalctl"
sudo journalctl \
--flush \
--rotate \
--vacuum-time=1s
else
echo "JournalCTL not found"
fi
# remove zipped logs
echo "Delete zipped logs"
sudo rm -rf /var/log/*.gz