Skip to content

Instantly share code, notes, and snippets.

@JPaulMora
Created February 7, 2019 18:05
Show Gist options
  • Save JPaulMora/56f70c03e9eeeb0a6e061673bb4ea161 to your computer and use it in GitHub Desktop.
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.
#!/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