blob: e86d396db74835ba2dbab3156e4054fa3f8d1fdd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#!/bin/sh
# get chrony sync status
PREFIX="chrony stat: "
bailout(){
echo "${PREFIX}ERROR --- $*" >&2
exit 1
}
KEY=$(awk '$1 ~ /^commandkey$/ { print $2; exit}' /etc/chrony/chrony.conf)
PASSWORD=`awk '$1 ~ /^'$KEY'$/ {print $2; exit}' /etc/chrony/chrony.keys`
command=sources
command_helper(){
/usr/bin/chronyc <<-EOF
password $PASSWORD
$command
EOF
}
show_help(){
cat << EOF
Usage $0 [ --full | --bool | --skew | --short-skew | --help ]
--full or no argument: show server name and verbose status
--bool show server name and
a) true, if timesource is currently synced
b) false otherwise
--skew show servername and
a) estimated error, if timesource is currently synced
b) false otherwise
--short-skew show estimated error, if timesource is currently synced
suppress all other servers
EOF
}
get_status(){
while read status server info; do
case $status in
'^*') echo -e "$server\tsynchronized `echo $info | sed s/'.*]'//g`" ;;
'^+') echo -e "$server\twaiting" ;;
'^?') echo -e "$server\tunreacheable" ;;
'^x') echo -e "$server\terror" ;;
'^~') echo -e "$server\tbad time" ;;
'=*'|'=+'|'=?'|'=x'|'=~') echo "peer : $status" ;;
'#*'|'#+'|'#?'|'#x'|'#~') echo "local : $status" ;;
esac
done
}
get_bool(){
while read status server info; do
case $status in
'^*') echo -e "$server\ttrue" ;;
'^'*)
echo -e "$server\tfalse" ;;
esac
done
}
get_skew(){
while read status server info; do
case $status in
'^*') echo -e "$server\t`echo $info | sed -e s/'.*]'//g -e s/"^\ "//g -e s@'+/- '@@g`" ;;
'^'*)
echo -e "$server\tundef" ;;
esac
done
}
get_short_skew(){
while read status server info; do
case $status in
'^*') echo $info | sed -e s/'.*]'//g -e s/"^\ "//g -e s@'+/- '@@g ;;
esac
done
}
/bin/pidof chronyd > /dev/null || bailout " chronyd is not running "
case $1 in
--help)
show_help
exit 0
;;
--bool)
command_helper | while read l ; do get_bool "$l"; done
exit 0
;;
--skew)
command_helper | while read l ; do get_skew "$l"; done
exit 0
;;
--short-skew)
command_helper | while read l ; do get_short_skew "$l"; done
exit 0
;;
*|'')
command_helper | while read l ; do get_status "$l"; done
exit 0
;;
esac
|