diff options
author | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2016-11-10 08:05:01 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2016-11-10 08:14:37 +0000 |
commit | 37af4954365ee745bd83844ee178ead3f7747bfc (patch) | |
tree | 7de2d4b5cd3e92096a4ddb0cbbf4069c3bb3ea93 /tcwg-cleanup-stale-containers.sh | |
parent | 4ff2601f68219666842e56f4361dafe399a9accb (diff) |
tcwg-cleanup-stale-containers: Handle "days" output from "docker ps"
Change-Id: Ia093265c5220910f54d792c8b0fc27f3086bbbbc
Diffstat (limited to 'tcwg-cleanup-stale-containers.sh')
-rwxr-xr-x | tcwg-cleanup-stale-containers.sh | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/tcwg-cleanup-stale-containers.sh b/tcwg-cleanup-stale-containers.sh index 20d5272a..9da6445f 100755 --- a/tcwg-cleanup-stale-containers.sh +++ b/tcwg-cleanup-stale-containers.sh @@ -23,7 +23,7 @@ if $verbose; then fi if [ "$hours" -lt "1" ]; then - echo "ERROR: Refusing to delete containers that are $hours days old" + echo "ERROR: Refusing to delete containers that are $hours hours old" exit 1 fi @@ -31,8 +31,15 @@ echo "Container report before:" docker ps $docker_ps_opts rm_containers=() -for container in $(docker ps --format "{{.ID}} {{.RunningFor}}" $docker_ps_opts | grep "hour" | cut -d" " -f 1); do - if [ "$(docker ps --format "{{.ID}} {{.RunningFor}}" $docker_ps_opts | grep "$container" | cut -d" " -f 2)" -gt "$hours" ]; then +for container in $(docker ps --format "{{.ID}} {{.RunningFor}}" $docker_ps_opts | grep "hour\|day" | cut -d" " -f 1); do + container_days="$(docker ps --format "{{.ID}} {{.RunningFor}}" $docker_ps_opts | grep "$container [0-9]\+ day" | cut -d" " -f 2)" + if [ x"$container_days" = x"" ]; then container_days="0"; fi + + container_hours="$(docker ps --format "{{.ID}} {{.RunningFor}}" $docker_ps_opts | grep "$container [0-9]\+ hour" | cut -d" " -f 2)" + if [ x"$container_hours" = x"" ]; then container_hours="0"; fi + + container_hours=$(($container_days*24 + $container_hours)) + if [ "$container_hours" -gt "$hours" ]; then rm_containers=("${rm_containers[@]}" $container) fi done |