Skip to content

Instantly share code, notes, and snippets.

@mill1000
Last active April 17, 2022 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mill1000/d143bb8dfec08f287a71c325034d1bc4 to your computer and use it in GitHub Desktop.
Save mill1000/d143bb8dfec08f287a71c325034d1bc4 to your computer and use it in GitHub Desktop.
Scripts to generate NTP Visualizations and pruning old stats files.
[Unit]
Description=Generate ntpviz webpage and plots
Documentation=man:ntpviz(1)
ConditionACPower=true
[Service]
User=ntp
Group=ntp
Type=oneshot
ExecStart=/usr/local/bin/ntpviz --name %H -d /var/log.hdd/ntpstats/ -o /var/www/ntpviz
ExecStartPost=/usr/local/bin/ntpviz_prune
# Hardening taken from logrotate.service
PrivateDevices=true
PrivateTmp=true
ProtectControlGroups=true
ProtectKernelModules=true
ProtectSystem=full
RestrictRealtime=true
[Unit]
Description=Daily ntpviz generation
Documentation=man:ntpviz(1)
[Timer]
OnCalendar=daily
AccuracySec=12h
Persistent=true
[Install]
WantedBy=timers.target
#! /bin/bash
echo "Pruning old and compressed ntpstats files."
# Prune logs in ramdisk over a day old
find /var/log/ntpstats/ -type f -mtime +1 | sort | while read FILENAME
do
echo "Pruning '$FILENAME' due to age."
rm $FILENAME
done
# Prune logs on disk over a week old
find /var/log.hdd/ntpstats/ -type f -mtime +7 | sort | while read FILENAME
do
echo "Pruning '$FILENAME' due to age."
rm $FILENAME
done
# Prune uncompressed logs that have a compressed copy
find /var/log.hdd/ntpstats/ -type f -name "*.gz" | sort | while read FILENAME
do
BASE=${FILENAME%.gz}
if [[ -f $BASE ]]; then
echo "Pruning '$BASE' since '$FILENAME' exists."
rm $BASE
fi
done
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment