v-get-sys-timezone 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. # info: get system timezone
  3. # options: [FORMAT]
  4. #
  5. # The function to get system timezone
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. format=${1-shell}
  11. # Includes
  12. source $VESTA/func/main.sh
  13. #----------------------------------------------------------#
  14. # Action #
  15. #----------------------------------------------------------#
  16. # Checking timesonze on RHEL/CentOS
  17. if [ -f "/etc/sysconfig/clock" ]; then
  18. source /etc/sysconfig/clock
  19. # Checking timezone on Debian/Ubuntu
  20. elif [ -f "/etc/timezone" ]; then
  21. ZONE=$(cat /etc/timezone)
  22. # Checking symlynks
  23. elif [ -h /etc/localtime ]; then
  24. ZONE=$(readlink /etc/localtime | sed "s%.*share/zoneinfo/%%")
  25. # Parsing zoneinfo (very slow)
  26. else
  27. checksum=$(md5sum /etc/localtime | cut -d' ' -f1)
  28. ZONE=$(find /usr/share/zoneinfo/ -type f -exec md5sum {} \; |\
  29. grep "^$checksum" | sed "s/.*\/usr\/share\/zoneinfo\///" | head -n 1)
  30. fi
  31. echo $ZONE
  32. #----------------------------------------------------------#
  33. # Vesta #
  34. #----------------------------------------------------------#
  35. exit