|
#!/bin/bash |
|
|
|
Help() { |
|
echo "Add description of the script functions here." |
|
echo |
|
echo "Syntax: chrony-status.sh [-c|f|h|p]" |
|
echo "options:" |
|
echo "c Add the config file to the output." |
|
echo "f <file> The name & location of the output file." |
|
echo "h Print this Help." |
|
echo "s Do not Print the report to the terminal." |
|
echo |
|
} |
|
|
|
ARCHIVE="false" |
|
CONFIG="false" |
|
PRINT="false" |
|
WEB="true" |
|
WEBAN="false" |
|
|
|
while getopts ":achswWf:" flag |
|
do |
|
case "${flag}" in |
|
a) ARCHIVE="true";; |
|
c) CONFIG="true";; |
|
h) Help |
|
exit;; |
|
s) PRINT="false";; |
|
w) WEB="true";; |
|
W) WEBAN="true";; |
|
f) FILE=${OPTARG};; |
|
\?) echo "Error: Invalid Option!" |
|
Help |
|
exit;; |
|
esac |
|
done |
|
|
|
if [ -z ${FILE} ]; then |
|
FILE=/var/lib/chrony-status/time.txt |
|
fi |
|
|
|
if [ ! -d /var/lib/chrony-status ]; then |
|
echo "Creating /var/lib/chrony-status" |
|
sudo mkdir -p /var/lib/chrony-status |
|
sudo chown pi:www-data /var/lib/chrony-status |
|
fi |
|
|
|
echo "The Odin Network Time Service on `cat /etc/hostname` (`hostname -I |awk '{print $1}'`)" > $FILE |
|
echo -n "Current Time : " >> $FILE |
|
echo `date` >> $FILE |
|
echo -n "Load Average : " >> $FILE |
|
cat /proc/loadavg |awk '{ print $1", "$2", " $3 }' >> $FILE |
|
echo -n "System Uptime : " >> $FILE |
|
uptime -p |sed 's/up //g' >> $FILE |
|
echo -n "Process Uptime : " >> $FILE |
|
ps -p `sudo cat /var/run/chrony/chronyd.pid` -o etime= |sed 's/ //g' >> $FILE |
|
echo -n "CPU Temperature : " >> $FILE |
|
/usr/bin/vcgencmd measure_temp | awk -F "[=']" '{print($2 * 1.8)+32}' >> $FILE |
|
echo "" >> $FILE |
|
|
|
echo "Server Tracking" >> $FILE |
|
chronyc tracking >> $FILE |
|
echo -n "Software : " >> $FILE |
|
chronyc --version |awk '{ print $4" "$2 }' >> $FILE |
|
echo "" >> $FILE |
|
|
|
echo "Server Clients" >> $FILE |
|
sudo chronyc clients |awk '!/^localhost/' |awk '!/^127.0.0.1/' |grep -v time.*local >> $FILE |
|
echo "" >> $FILE |
|
|
|
echo "Server Sources" >> $FILE |
|
sudo chronyc -N sources >> $FILE |
|
echo "" >> $FILE |
|
|
|
echo "Server Sources Stats" >> $FILE |
|
sudo chronyc -N sourcestats >> $FILE |
|
echo "" >> $FILE |
|
|
|
echo "Server Sources Auth" >> $FILE |
|
sudo chronyc -N authdata >> $FILE |
|
echo "" >> $FILE |
|
|
|
if [ ${WEB} == "true" ]; then |
|
cp $FILE /var/www/html/ |
|
fi |
|
|
|
if [ ${CONFIG} == "true" ]; then |
|
echo "Server Config file (/etc/chrony/chrony.conf)" >> $FILE |
|
echo "==============================================================================" >> $FILE |
|
cat /etc/chrony/chrony.conf |sed "/^#/d" |sed '/^$/d' >> $FILE |
|
fi |
|
|
|
if [ ${ARCHIVE} == "true" ]; then |
|
if [ -f /var/lib/chrony-status/status-`date +%Y%m`.db ]; then |
|
echo "insert into logs values('`date`','`cat /var/www/html/time.txt`');" |sqlite3 /var/lib/chrony-status/status-`date +%Y%m`.db |
|
else |
|
echo "create table logs (datetime text, log text);" |sqlite3 /var/lib/chrony-status/status-`date +%Y%m`.db |
|
echo "insert into logs values('`date`','`cat /var/www/html/time.txt`');" |sqlite3 /var/lib/chrony-status/status-`date +%Y%m`.db |
|
fi |
|
fi |
|
|
|
if [ ${WEBAN} == "true" ]; then |
|
sudo cp $FILE /var/www/html/ |
|
fi |
|
|
|
if [ ${PRINT} == "true" ]; then |
|
cat ${FILE} |
|
fi |