Skip to content

Instantly share code, notes, and snippets.

@tsonglew
Created October 23, 2020 02:32
Show Gist options
  • Save tsonglew/f973415a928b55c24e0d3614d44d62e3 to your computer and use it in GitHub Desktop.
Save tsonglew/f973415a928b55c24e0d3614d44d62e3 to your computer and use it in GitHub Desktop.
remove docker containers log on remote machines
#!/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