XK0-004 · Question #449
A virtual machine logs al limes using UTC The systems administrator would like to have one script that outputs times that are in the Amenca/Chicago time zone. Which of the following would the administ
The correct answer is D. timedatect1 set-timezone "America/Chicago" $$ date >> mylog.txt. The timedatectl command sets the system timezone so that subsequent date commands in a script output timestamps in the desired local timezone.
Question
A virtual machine logs al limes using UTC The systems administrator would like to have one script that outputs times that are in the Amenca/Chicago time zone. Which of the following would the administrator MOST likely use in the script to accounts.
Options
- Aecho 'env TZ=America/Chicago date' >> mylog.-xt
- Bhwclock --localtime ?-mylog.txt
- Cdate -d 'Tz="America/Chicago" now' >> mylog.txt
- Dtimedatect1 set-timezone "America/Chicago" $$ date >> mylog.txt
How the community answered
(47 responses)- A4% (2)
- B17% (8)
- C6% (3)
- D72% (34)
Why each option
The timedatectl command sets the system timezone so that subsequent date commands in a script output timestamps in the desired local timezone.
This command writes a literal string to a file rather than executing any command, producing no actual date output in the log.
hwclock --localtime reads the hardware clock in local mode but does not produce formatted, timezone-specific output suitable for appending to a log file.
Embedding a timezone inside the date -d argument string in this format is not valid GNU date syntax; the TZ variable must be set in the shell environment before the command, not nested inside the -d date string.
timedatectl set-timezone configures the system's active timezone to America/Chicago, after which the date command will format output using that zone. Chaining these operations in a script and redirecting to a log file produces timezone-correct timestamps without requiring manual TZ variable exports on every invocation.
Concept tested: Linux timezone configuration with timedatectl for script output
Source: https://man7.org/linux/man-pages/man1/timedatectl.1.html
Topics
Community Discussion
No community discussion yet for this question.