寻找脚本来(1)检查 ntp 的状态和(2)它是否在给定时间服务器(例如123.456.789.10)的+/- 1 秒内。(3)另外,还要检查系统时间,看时区设置是否正确(例如PST)
这是我到目前为止所拥有的,检查 ntp 的状态:
#!/bin/bash
if [[ ! -x /usr/bin/ntpstat ]]
then
echo "ntpstat is NOT installed: please install it"
exit 3
res=$(/usr/bin/ntpstat)
rc=$?
case $rc in
0 )
echo "clocks are synchronized"
;;
1 )
echo "WARNING: clocks are NOT synchronized"
;;
2 )
echo "CRITICAL: NTPD IS DOWN -- NO STATUS"
;;
esac
Run Code Online (Sandbox Code Playgroud)