#!/bin/bash ntp_server="ro.pool.ntp.org" your_sudo_password="startpay" echo "$(timedatectl)" >> "$DN/log/add/start.log" # Synchronize system time with an NTP server # Run ntpdate command with sudo and provide the password echo "$your_sudo_password" | su -c "ntpdate \"$ntp_server\"" root # Get the current system time and hardware clock time system_time=$(date "+%Y-%m-%d %H:%M:%S.%N%:z") hardware_time=$(echo "$your_sudo_password" | su -c "hwclock --utc --show" root) # Extract the UNIX timestamp from the hardware time string system_timestamp=$(date +%s) hardware_timestamp=$(date -d "$hardware_time" +%s) echo "$(date +%H:%M:%S),000 INFO System Time: $system_time" >> "$DN/log/add/start.log" echo "$(date +%H:%M:%S),000 INFO System Timestamp: $system_timestamp" >> "$DN/log/add/start.log" echo "$(date +%H:%M:%S),000 INFO Hardware Time: $hardware_time" >> "$DN/log/add/start.log" echo "$(date +%H:%M:%S),000 INFO Hardware Timestamp: $hardware_timestamp" >> "$DN/log/add/start.log" # Calculate the time difference between system time and hardware clock time time_difference=$((system_timestamp - hardware_timestamp)) absolute_difference=${time_difference#-} echo "$(date +%H:%M:%S),000 INFO Time Difference: $time_difference" >> "$DN/log/add/start.log" echo "$(date +%H:%M:%S),000 INFO Absolute Difference: $absolute_difference" >> "$DN/log/add/start.log" # Set the maximum allowable time difference (in seconds) max_time_difference=60 # Check if the time difference is within the acceptable range if ((time_difference > max_time_difference)); then # Update the hardware clock with the synchronized system time echo "$your_sudo_password" | su -c "hwclock --systohc" root # Print a message indicating that time synchronization has been performed echo "$(date +%H:%M:%S),000 INFO System time has been synchronized" >> "$DN/log/add/start.log" echo "$(timedatectl)" >> "$DN/log/add/start.log" else echo "$(date +%H:%M:%S),000 INFO Time synchronization not performed. Hardware clock time differs significantly from system time" >> "$DN/log/add/start.log" fi