#!/bin/bash # Rocky9 compatible . /usr/src/k_framework/main.sh VERSION="1.1.1" SCRIPT_NAME="Set Server time zone to UTC" k_start k_detect_os if [[ $ROCKY9 == 1 ]]; then timedatectl set-timezone Etc/UTC else # Other OS, not Rocky9 if (( centos_version > 6 )); then timedatectl set-timezone UTC else echo 'ZONE="UTC"' > /etc/sysconfig/clock cp -f /usr/share/zoneinfo/UTC /etc/localtime # These two probably will not do anything, just in case /usr/sbin/tzdata-update /sbin/hwclock --systohc # Without rsyslog restart (or system reboot), /var/log/secure (and other rsyslog controlled logs) will show old time # This can confuse fail2ban among other things /sbin/service rsyslog restart > /dev/null fi fi # check if date | grep -Fq 'UTC'; then report "Server timezone has been set to UTC" 0 else report "Failed to set server timezone to UTC" 1 EXIT_CODE=1 fi k_exit $EXIT_CODE