#!/bin/bash ##### checktime.sh / rb / 2025 ##### check time between a webserver and the localtime uri="https://borwinius.de" ##### check if curl or wget and get webservertime if [ -x $(which curl) ]; then curl -skI $uri -o /dev/null || exit 60 timestring=$(curl --head $uri 2>>/dev/null | grep -e Date: | cut -d: -f2-4) else wget --no-check-certificate --spider $uri -q -O - 2>&1 || exit 5 timestring=$(wget -S $uri -q -O - 2>&1 | grep -e Date: | head -1 | cut -d: -f2-4) fi #timestring="Mon, 13 Jan 2025 12:22:33 GMT" echo $timestring webseconds=$(date -d "$timestring" +%s) echo $webseconds ##### get localtime localseconds=$(date +%s) echo $localseconds ##### check if the difference gt 5 minutes difference=$(expr $webseconds - $localseconds ) # echo $difference if [ "${difference##*[+-]}" -ge 300 ]; then echo "ERROR: $difference greater then 300 secs" exit 1 else echo "OK: $difference smaller then 300 secs " fi