From f48f4cc6e513773fac094d6b3115954deaeacbc7 Mon Sep 17 00:00:00 2001 From: crcro Date: Mon, 12 Sep 2016 11:43:34 +0300 Subject: [PATCH] update 1 ntp server --- snmp/ntp-server.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/snmp/ntp-server.sh b/snmp/ntp-server.sh index dbf0fb9..08c8d1a 100755 --- a/snmp/ntp-server.sh +++ b/snmp/ntp-server.sh @@ -2,13 +2,15 @@ ################################################################ # copy this script to somewhere like /opt and make chmod +x it # # edit your snmpd.conf and include # -# extend ntp-server /opt/ntp-server.sh # +# extend ntpdserver /opt/ntp-server.sh # # restart snmpd and activate the app for desired host # # please make sure you have the path/binaries below # ################################################################ # Binaries and paths required # ################################################################ +BIN_NTPD='/usr/sbin/ntpd' BIN_NTPQ='/usr/sbin/ntpq' +BIN_NTPDC='/usr/sbin/ntpdc' BIN_GREP='/usr/bin/grep' BIN_TR='/usr/bin/tr' BIN_CUT='/usr/bin/cut' @@ -16,6 +18,8 @@ BIN_SED='/usr/bin/sed' ################################################################ # Don't change anything unless you know what are you doing # ################################################################ +VER=`$BIN_NTPD --version` + CMD0=`$BIN_NTPQ -c rv | $BIN_GREP -Eow "stratum=[0-9]+" | $BIN_CUT -d "=" -f 2` echo $CMD0 @@ -27,7 +31,13 @@ do echo ${array["$value"]} | $BIN_CUT -d "=" -f 2 done -CMD2=`$BIN_NTPQ -c iostats localhost | $BIN_TR -d ' ' | $BIN_TR '\n' ','` +if [[ "$VER" =~ '4.2.8p8' ]] +then + CMD2=`$BIN_NTPQ -c iostats localhost | $BIN_TR -d ' ' | $BIN_TR '\n' ','` +else + CMD2=`$BIN_NTPDC -c iostats | $BIN_TR -d ' ' | $BIN_TR '\n' ','` +fi + IFS=',' read -r -a array <<< "$CMD2" for value in 0 1 2 3 5 6 7 8