Created
October 23, 2020 02:32
-
-
Save tsonglew/f973415a928b55c24e0d3614d44d62e3 to your computer and use it in GitHub Desktop.
remove docker containers log on remote machines
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 | |
echo "Will purge logs on ${IPS[@]}" | |
echo "Using SSHUSER: ${SSHUSER}, SSHKEY_PATH: ${SSHKEY_PATH}, ${SSHPORT}" | |
for ip in "${IPS[@]}"; | |
do | |
echo "Running purge docker on ${ip}" | |
ssh -i ${SSHKEY_PATH} -o StrictHostKeyChecking=no ${SSHUSER}@${ip} -p${SSHPORT} << 'ENDSSH' | |
export DOCKER_PATH_PREFIX="/var/lib/docker/containers/" | |
for id in $(sudo ls ${DOCKER_PATH_PREFIX}); | |
do | |
for logfile in $(sudo ls "${DOCKER_PATH_PREFIX}${id}" | grep "log"); | |
do | |
sudo rm ${DOCKER_PATH_PREFIX}${id}/${logfile} | |
done | |
done | |
ENDSSH | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment