Created
February 7, 2019 18:05
-
-
Save JPaulMora/56f70c03e9eeeb0a6e061673bb4ea161 to your computer and use it in GitHub Desktop.
Get docker container IDs based on date and if they're exited or not.
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 | |
IFS=$'\n' | |
TODAY=$(/bin/date +"%Y-%m-%d") | |
#CONTAINERS=$(sudo docker ps -a -f ancestor=ubuntu --format "table {{.ID}} {{.CreatedAt}} {{.Status}}") | |
/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 | |
then | |
/bin/echo ${array[0]} | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment