Created
March 18, 2024 21:24
-
-
Save pfrozi/41b11fefb42d7e25500348f62f985e54 to your computer and use it in GitHub Desktop.
Get all the host's containers and show the log size of each one. Then truncate the log when the user presses any key.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
container_ids=$(docker ps -aq) | |
for id in $container_ids; do | |
log_size=$(docker inspect --format='{{.LogPath}}' $id | xargs du -sh | awk '{print $1}') | |
name=$(docker inspect --format='{{.Name}}' $id | sed 's/\///') | |
echo "Container ID: $id" | |
echo "Container Name: $name" | |
echo "Log Size: $log_size" | |
echo | |
read -p "Press enter to clear . . ." | |
truncate -s 0 $(docker inspect --format='{{.LogPath}}' $id) | |
read -p "Log was cleared! Press enter to continue . . ." | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment