fix: 优化 chrony 时间源检查逻辑以正确识别同步状态
This commit is contained in:
1 parent
756b8f6004
commit
a3a01fc80f
1 file changed
+5
-2
+5
-2
@@ -252,8 +252,11 @@ chrony_synced() {
|
||||
local sources
|
||||
sources=$(timeout 10 chronyc -n sources) || return 1
|
||||
printf '%s\n' "$sources" | awk -v ip="$CONTROLLER_IP" '
|
||||
$1=="^*" && $2==ip {found=1}
|
||||
$1 ~ /^[\^=]/ && $2!=ip {bad=1}
|
||||
# 时间源标记只有两个字符(如 ^*、^?、=+);排除表头的等号分隔线。
|
||||
length($1)==2 && (substr($1,1,1)=="^" || substr($1,1,1)=="=") {
|
||||
if($1=="^*" && $2==ip) found=1
|
||||
if($2!=ip) bad=1
|
||||
}
|
||||
END{exit !(found && !bad)}'
|
||||
}
|
||||
check 2 'chrony 已安装' 'chrony 未安装(第1步:安装软件)' rpm -q chrony
|
||||
|
||||
Reference in new issue
Block a user