#!/bin/bash # maravento.com # ################################################################################ # # Hardware Clock Sync # Syncs the hardware clock (hwclock) with the system clock. # Intended to run at boot via cron (@reboot). # ################################################################################ set -uo pipefail # path for cron export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin # root check if [ "$(id -u)" != "0" ]; then echo "ERROR: This script must be run as root -- abort" exit 1 fi # prevent overlapping runs SCRIPT_LOCK="/var/lock/$(basename "$0" .sh).lock" (umask 077; : >> "$SCRIPT_LOCK") exec 200>"$SCRIPT_LOCK" if ! flock -n 200; then echo "ERROR: script $(basename "$0") is already running -- abort" exit 1 fi # dependencies for dep in util-linux coreutils; do if ! dpkg -s "$dep" &>/dev/null; then echo "ERROR: dependency '$dep' is not installed -- abort" >&2 exit 1 fi done echo "Update HWClock. Wait..." hwclock -w || echo "WARNING: hwclock -w failed (VM or container?)" echo "HWClock Update: $(date)" | tee -a /var/log/syslog