I am sshing into a server in a shell script and running some docker commands. However some of the commands fail in docker version 1.7. I have a fix for 1.7, but it takes a lot longer to run the shell script if I use it all the time. So I want to check for that version, and if it's 1.7 fall back to the slower script. Else run the nice fast version.
Thinking something like
if ssh -l root $1 "docker -v === '1.7.*'"
then
echo "Docker version 1.7!"
else
echo "Docker version not 1.7!"
fi
Obviously this doesn't work. Any ideas?
Perhaps, sometime required version range for check. As variant possible solution:
SERVER_VERSION=$(docker version -f "{{.Server.Version}}")
SERVER_VERSION_MAJOR=$(echo "$SERVER_VERSION"| cut -d'.' -f 1)
SERVER_VERSION_MINOR=$(echo "$SERVER_VERSION"| cut -d'.' -f 2)
SERVER_VERSION_BUILD=$(echo "$SERVER_VERSION"| cut -d'.' -f 3)
if [ "${SERVER_VERSION_MAJOR}" -ge 19 ] && \
[ "${SERVER_VERSION_MINOR}" -ge 0 ] && \
[ "${SERVER_VERSION_BUILD}" -ge 3 ]; then
echo "Docker version >= 19.0.3 it's ok"
else
echo "Docker version less than 19.0.3 can't continue"
exit 1
fi
You can use:
if [[ $(ssh -l root "$1" 'docker -v') == *" 1.7."* ]]; then
echo 'Docker version 1.7!'
else
echo 'Docker version not 1.7!'
fi
ssh
command using command substitution $(...)
==
or =
but not ===
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With