Skip to content

Instantly share code, notes, and snippets.

@pfrozi
Created March 18, 2024 21:24
Show Gist options
  • Save pfrozi/41b11fefb42d7e25500348f62f985e54 to your computer and use it in GitHub Desktop.
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.
#!/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