diff options
author | Bjoern Buerger <b.buerger@pengutronix.de> | 2007-04-10 11:34:24 +0000 |
---|---|---|
committer | Bjoern Buerger <b.buerger@pengutronix.de> | 2007-04-10 11:34:24 +0000 |
commit | 70d2d88052adfec80711781af502bcece8128f0c (patch) | |
tree | 5f56a44c04365e9e87c7303cfa09b1e0bce6fbbf /generic | |
parent | b7180d11044c28205fc87ee5a08541fdf3035c0b (diff) | |
download | ptxdist-70d2d88052adfec80711781af502bcece8128f0c.tar.gz ptxdist-70d2d88052adfec80711781af502bcece8128f0c.tar.xz |
git-svn-id: https://svn.pengutronix.de/svn/ptxdist/trunks/ptxdist-trunk@7086 33e552b5-05e3-0310-8538-816dae2090ed
Diffstat (limited to 'generic')
-rwxr-xr-x | generic/usr/bin/chrony_stat | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/generic/usr/bin/chrony_stat b/generic/usr/bin/chrony_stat new file mode 100755 index 000000000..e86d396db --- /dev/null +++ b/generic/usr/bin/chrony_stat @@ -0,0 +1,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 |