System Administration

Time

Why is good timekeeping important?

Logfiles - timestamps

File creation/modification times

Programs which need absolute time - astronomical ephemerides

Security programs which have timeouts - Kerberos

Cluster of computers needing to have the same time

System Administration

Time

Two types of time:

Hardware time
Kept on the motherboard,
settable in BIOS.

System time
Kept by kernel, used by the
system

System Administration

Time

Ways to set time:

Manually – entered at the keyboard

Querying the hardware clock

Syncing to a time source

Network

Directly connected hardware (e.g. radio, GPS)

System Administration

Manually Setting Time

date

The date command returns the current system time when given no arguments.

A formatting template can be specified to print date/time different ways – useful for log files

If arguments are given, the date command will set the system time

date [MMDDhhmm[[CC]YY][.ss]]

Example:

date 020413542003

System Administration

Manually Setting Time
date

Exercises

Set the date on your system based on the reading on your watch:

# /bin/date 021014232004.00

Print out the month, date and year as ddmmmyyyy

# /bin/date +'%d%b%Y'

System Administration

Manually Setting Time
hwclock

The hwclock command returns the current hardware time when given no arguments.

Hwclock can set both the system clock and the hardware clock:

hwclock - -hctosys

hwclock - -systohc

hwclock - -set date=date string

System Administration

Manually Setting Time
hwclock

hwclock is often run on boot-up and shutdown

/etc/rc.d/rc.sysinit

/etc/rc.d/init.d/halt

System Administration

Manually Setting Time
hwclock

Exercise

Use hwclock to set the system time from the hardware time:

# /bin/date 02101043
# /bin/date
# /sbin/hwclock --hctosys

System Administration

Syncing Time

ntp

NTP, the Network Time Protocol, allows time clients to sync their clocks with time servers.

NTP allows for automating the setting of your clock

NTP provides much more accurate time stamps

NTP servers are layered by strata. Stratum 1 servers are connected to hardware time sources. Stratum 2 servers sync with these and so on...

System Administration

Syncing Time

ntp

You can configure your computer to be a client or a peer

Simplest configuration:

Add the following to /etc/ntp.conf

server tick.iastate.edu

server tock.iastate.edu

server chime.iastate.edu

This instructs the ntp daemon to act as a client and use these three machines as servers

System Administration

Syncing Time

ntpdate

Create the file /etc/ntp/step-tickers with the entry

time.iastate.edu

When ntp is started on boot-up, the ntpdate command will use this file to give the clock an initial value.

If this isn't done, and the time difference is too great, ntp will exit

System Administration

Syncing Time

ntpdate

If you do not need up-to-the-second time synchronization, you can use the command ntpdate as a one-shot to set the time once.

ntpdate -u time.iastate.edu

You can also add ntpdate to your crontab file to periodically sync the time

0 8,18 * * * /usr/sbin/ntpdate -u time.iastate.edu

System Administration

Time Zones

What time it is depends on where your server is physically located.

System clock stores time in seconds since the epoch (1970) and this may be in Universal Time Coordinates (UTC)

Your system needs a way to convert this to something humans can understand

System Administration

Time Zones

The date command depends on the time and localtime C functions to convert the seconds since the epoch to date, hours, minutes and seconds

localtime depends on time zone information

Information for all time zones is stored in /usr/share/zoneinfo

A copy of the zone data for the machine is in /etc/localtime

System Administration

Time Zones

The command zdump can be used to determine when a system believes DST begins and ends

/usr/sbin/zdump -v etc/localtime | grep 2008

When time zone info changes, Red Hat will update the tzdata package

For other systems, you may have to download the zoneinfo files and “compile” them with the command zic

2004-02-04T15:09:20