Skip to content

Instantly share code, notes, and snippets.

@JPaulMora
Created February 7, 2019 18:07
Show Gist options
  • Save JPaulMora/8593d735fd8583c0bcbfb21d4dce92f0 to your computer and use it in GitHub Desktop.
Save JPaulMora/8593d735fd8583c0bcbfb21d4dce92f0 to your computer and use it in GitHub Desktop.
Script that logs into new docker shell
#!/bin/bash
/usr/bin/docker run -ti ubuntu
IFS=$'\n'
TODAY=$(/bin/date +"%Y-%m-%d")
/usr/bin/docker ps -a -f ancestor=ubuntu --format "{{.ID}} {{.CreatedAt}} {{.Status}}" | while read cont
do
IFS=' '
array=($cont)
# if [[ ${array[1]} < $TODAY ]] && /bin/grep -q "Exited" <<<$cont
if /bin/grep -q "Exited" <<<$cont
then
# /bin/echo deleting container ${array[0]}
/usr/bin/docker rm ${array[0]}
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment