I was looking for a way to save in a variable, the monit version installed in my server
If I use the command monit -V
the result is very verbose, like this:This is Monit version 5.6
Copyright (C) 2001-2013 Tildeslash Ltd. All Rights Reserved.
Instead I would like to only 5.6
So I write a small bash script with a Regular Expression to find and asve in a variable only that 5.6
.#!/bin/bash
m_v="$(monit -V)"
for f in $m_v ; do
if [[ $f =~ ^[+-]?[0-9]+\.?[0-9]*+\.?[0-9]*$ ]]; then
monit_version=$f
fi
done
echo $monit_version