我正在尝试使用案例逻辑检查 $VERSION,但有一些问题。
$VERSION 可以是“主机拒绝连接”、“0,4,1,101 2013-05-18”或其他一些版本,例如“0,4,1,102 2013-09-18”
在我的测试中,当 $VERSION 为“0,4,1,101 2013-05-18”时,我似乎总是遇到“其他问题”......
#!/bin/bash
HOSTNAME=$1
VERSION=$(/usr/local/nagios/libexec/check_nrpe -H servername01 -c checkversion)
echo "$VERSION" >> /var/log/dig-nscp-install.log
NOW=$(date '+%Y-%m-%d -- %H:%M')
LOGFILE=/var/log/dig-nscp-install.log
#if [ "$TRVER" == "Connection refused by host" ]; then
# echo "$NOW : Version $VERSION already installed on HOSTNAME!" >> /var/log/dig-nscp-install.log
#else
# echo "$NOW : Powershell install script initiated to install version $VERSION on $HOSTNAME!" >> /var/log/dig-nscp-install.log
# /usr/local/nagios/libexec/check_nrpe -H servername02 -t 300 -c install_nscp_0.4.101 -a $HOSTNAME
#
#fi
case $VERSION in
"Connection refused by host")
echo "$NOW : Powershell script initiated to install version $VERSION on $HOSTNAME!" >> /var/log/dig-nscp-install.log
;;
"0,4,1,101 2013-05-18")
echo "$NOW : Version $VERSION already installed on HOSTNAME!" >> /var/log/dig-nscp-install.log
;;
*)
echo "$NOW : Some other problem" >> /var/log/dig-nscp-install.log
;;
esac