#!/bin/bash
exec >> >(tee -a "${0%.*}".log.txt 2>&1)
LOGFILE="/var/log/everything.log"
COUNT=50
WAIT_MINUTES=42
BUG=0
for ((i=1; i<=COUNT; i++)); do
if [ $(date +%H) -lt 3 ]; then
TARGET_TIME=$(date +"%Y-%m-%d 02:53:00")
else
TARGET_TIME=$(date -d "tomorrow" +"%Y-%m-%d 02:53:00")
fi
echo "[$(date)] Iteration $i: translating time to $(date)"
date -s "$TARGET_TIME"> /dev/null
hwclock -uw
dnsd_tool --sync-date-time arg
echo "[$(date)] Time up to $TARGET_TIME"
echo "[$(date)] Start monitoring $LOGFILE for $WAIT_MINUTES minutes"
TIMEOUT=$((WAIT_MINUTES*60))
# echo "TODO 1"
FOUND=0
while read -r line; do
if [[ "$line" == *"Validating frame failed"* ]]; then
echo "[$(date)] ***Est probitie, nashel stroky***"
FOUND=1
BUG=1
# sleep 1
# echo " $FOUND TODO 3 "
# break
fi
done < <(timeout $TIMEOUT tail -n0 -F "$LOGFILE")
# echo "TODO 2"
# echo " $FOUND TODO 4 "
wait
if [[ $FOUND -eq 0 ]]; then
echo "[$(date)] In this iteretion messege about the error not found"
# echo " $FOUND $COUNT $WAIT_MINUTES "
# break
else
echo "[$(date)] There was a bug in this iteration"
# break
fi
done
if [[ $BUG -eq 0 ]]; then
echo "[$(date)] Test passed, no errors found."
else
echo "[$(date)] The test failed, see the "${0%.*}".log.txt"
fi
echo "End of script ©Oleg+ChatGpt"
echo "nonpaBuJL MapaT"