Shell script to restart exited container with specific exit code 255 and 137

Viewed 24

Here , i want to restart only the container which are exited with error code 137 and 255 and i don't want other containers to restart. I tried creating a script but i am stucked in between . Please help me with this.

#!/bin/bash
code2=137
offlineContainers=`sudo docker ps -a -q --filter "status=exited"`
for container in $offlineContainers
do
dockerror=`sudo docker inspect $offlineContainers --format='{{.State.ExitCode}}'`
  if [ $dockerror == $code2 ]
  then
        echo "$(sudo docker restart $offlineContainer )"
        echo "container restarted"
else
       echo " dont restart"
  fi
done

Error:- ./exited.sh: line 7: [: too many arguments

Thanks

0 Answers
Related