dropdown menu

AIX - DATE

date - time

Time synchronization:timed, ntpd, setclock
ntp is considered superior to timed.


NTP:
ntpd is a daemon that runs to keep your time up to date/time. For this you must configure ntp.conf so it will know where to get the date/time.
ntpdate is a command that will use ntp.conf to do an update now as opposed to waiting for ntpd to do it.
Translation: You want ntpd, you need to configure ntp.conf. You CAN use ntpdate to do manual updates.

should put this line to /etc/ntp.conf:
server timeserver.domain.com
driftfile /etc/ntp.drift
tracefile /etc/ntp.trace
...
...


Date change:
1. stopsrc -s xntpd
2. ntpdate <ntp server>                      <--ntpdate command will decline if xntpd is running
   4 Oct 14:20:07 ntpdate[491628]: step time server 200.200.10.100 offset -32.293912 sec
<<3. smit date>>
4. vi /etc/rc.tcpip
5. uncomment this line: start /usr/sbin/xntpd "$src_running"
6. startsrc -s xntpd

---------------------

Configuring NTP:

ON SERVER:
1. lssrc -ls xntpd                          <--Sys peer should show a valid server or 127.127.1.0.

If the server is "insane":
2. vi /etc/ntp.conf:
   Add:
      server 127.127.1.0
      Double check that "broadcast client" is commented out.

      stopsrc -s xntpd
      startsrc -s xntpd
     If it is a DB server, use the -x flag to prevent the clock from changing in a negative direction.
     Enter the following:startsrc -s xntpd -a "-x"

3. lssrc -ls xntpd                           <--check if the server is synched. It can take up 12 minutes


ON CLIENT:
1. ntpdate -d ip.address.of.server           <--verify there is a suitable server for synch
The offset must be less than 1000 seconds for xntpd to synch.
If the offset is greater than 1000 seconds, change the time manually on the client and run the ntpdate -d again.

If you get the message, "no server suitable for synchronization found", verify xntpd is running on the server (see above) and that no firewalls are blocking port 123.

2. vi /etc/ntp.conf                          <--specify your xntp server in /etc/ntp.conf, enter:
(Comment out the "broadcastclient" line and add server ip.address.of.server prefer.)
Leave the driftfile and tracefile at their defaults.

3. startsrc -s xntpd                          <--start the xntpd daemon:
(Use the -x flag if it is appropriate for your environment.)

4. vi /etc/rc.tcpip                            <--uncomment xntpd from /etc/rc.tcpip so it will start on a reboot.
Uncomment the following line:
      start /usr/sbin/xntpd "$src_running"
      If using the -x flag, add "-x" to the end of the line. You must include the quotes around the -x.

5. lssrc -ls xntpd            <--verify that the client is synched.
Sys peer should display the IP address or name of your xntp server. This process may take up to 12 minutes.
---------------------

NTP problem: No association ID's returned
# ntpq -p
No association ID's returned

This can mean different things, but mainly NTP server somehow cannot be reached.
(could be DNS resolution issues, something wrong in ntp.conf, or firewall...)
(Once I had special characters at the end of each line in ntp.conf, which was not shown by cat. It could be seen only with vi or cat -vet. After removing those and restarting xntpd everything was OK)

(Another time on VIO server both /etc/ntp.conf and /home/padmin/config/ntp.conf were there, but they were not identical. In this case either removing /etc/ntp.conf or making them identical and after that restarting xntpd as padmin: stopnetsvc xntpd and startnetsvc xntpd, resolved the problem.)

Below resolution works if server name could not be resolved:

It can be checked with this as well:
# ntpq -p <severname>

# tail /etc/ntp.conf
driftfile /etc/ntp.drift
tracefile /etc/ntp.trace
server timeserver.domain.com prefer
server timeserver2.domain.com

# ping timeserver.domain.com
0821-062 ping: host name timeserver.domain.com NOT FOUND

# tail /etc/netsvc.conf

hosts=local

# nslookup timeserver.domain.com
Server:  ns.domain.com
Address:  10.20.10.10

Name:    timeserver.domain.com
Address:  10.20.10.11

# vi /etc/netsvc.conf
-> hosts=local,bind4

# refresh -s xntpd

# ntpq -p
     remote           refid      st t when poll reach   delay   offset    disp
==============================================================================
sys_pmm-1        timeserver2     2 u   24   64    1    13.75    1.279 15875.0
timeserver2 .    hopf.           1 u   23   64    3    16.85   -5.670 7875.17

------------------
------------------
------------------

Time Zone variable:

Time Zone variable (TZ) is defined in /etc/environment (echo $TZ), and time zone can be specified in two formats: POSIX and Olson.

Olson:
It maintains a database for each time zone under the /usr/share/lib/zoneinfo.

# ls -l /usr/share/lib/zoneinfo/Europe
-rw-r--r--    1 bin      bin            2917 Sep 13 2013  Amsterdam
-rw-r--r--    1 bin      bin            1725 Sep 13 2013  Andorra
-rw-r--r--    1 bin      bin            2245 Sep 13 2013  Athens
...

This format uses known names of cities or regions. We can specify the time zone name in a simple, easy-to-understand format: TZ=America/New_York


Posix:
The POSIX time zone format is the traditionally used format for AIX systems. The advantage of POSIX is that you can easily and explicitly specify the time zone and daylight saving time (DST) manually.

DST: Daylight Saving Time (this means that we have to change our clock at spring/autumn)

The TZ variable specified in POSIX format contains all information required to identify the time zone, specify when to switch DST on and off, and specify the offset from Coordinated Universal Time (UTC). AIX internally does everything in UTC time, and any display of time to the users is based on the time zone and DST rules specified by TZ variable.

TZ format in POSIX: TZ = local_timezone,date,date
TZ=NFT-1DFT-2,M3.5.0,M10.5.0        <--DST is used
TZ=CUT                              <--DST is not used

Usually letter "D" means Daylight Saving Time (DST). The US rules have letters "S" for standard and "D" for DST.
For example America/New_York zone format in POSIX looks this way: EST5EDT,M3.2.0,M11.1.0  ("EST" and "EDT" shows these changes in the timezone)

if you see this:
NFT-1DFT-2,M3.5.0,M10.5.0

NFT             <--name of Standard Time (Oct. -> March)
-1              <--difference between standard time and UTC (or CUT) (it means between Oct. and March our time is behind 1 hour from UTC)
DFT             <--name of Daylight Saving Time (March -> Oct.)
-2              <--difference between DST and UTC (or CUT) (it means between March and Oct our time is behind 2 hour from UTC)

Start Daylight Saving Time:
M3              <--month 3 (March)
              <--5. occurence on that month
0               <--sunday

Stop Daylight Saving Time:
M10             <--month 10 (October)
5               <--5. occurence on that month
0               <--sunday

The "CUT0" is actually another POSIX $TZ value, not an Olson name,and it refers to constant UT+0h, with no DST, and constant abbreviation "CUT".

-----

In 'smit chtz_user' 2 terms are used for setting timezones:

Standard Time: time usually used from end of October until end of March
Daylight Saving Time: this is the time usually used from end of March until end of October

grep TZ /etc/environment                         checking TZ variable (echo $TZ works as well)
tail -1 /usr/share/lib/zoneinfo/Europe/Athens    to get some info regarding POSIX abbreviation from an Olson value
zdump Turkey                                     shows actual date at given zone (zdump CET works as well)
zdump -v CET | grep 2015                         getting info about DST changing date/time in the given year (idtst=0 means DST is turned off)

-----

TZ change:
smitty chtz_user (smitty chtz_date) or chtz
(here you can see timezone list: ls -l /usr/share/lib/zoneinfo)

for example:
chtz EST5EDT                                      <--it will change timezone to EST5EDT

Environment variables are examined when a command starts running. The environment of a process is not changed by altering the /etc/environment file. Any processes that were started prior to the change to the /etc/environment file must be restarted if the change is to take effect for those processes. If the TZ variable is changed, the cron daemon must be restarted, because this variable is used to determine the current local time.

22 comments:

cpguru21 said...

hello aix4adm!!!! Thank you for this awesome resource!

I am trying to save a logfile with a date in the name, and not having much luck. In my script I specify:
LOGFILE='rsync__`date`.log'
However this simply results in a file named rsync__`date`.log

I dont really care about the format of the date/time in the file name. Do you have any help for me?

Thanks,

aix said...

Hello cpguru21,

This worked for me: LOGFILE="rsync__`date`.log"
(Just change the ' to ") I tested it in ksh.

Hope this helps,
Balazs

cpguru21 said...

Thanks a bunch Balazs. So this worked well however now my log file has a bunch of spaces in the name which is not ideal. do you have a suggestion to get the date formatted in a way where it is something like rsync__2012010911:30?

Thanks!

cpguru21 said...

sorry Balazs, man page is wonderful thing. Im all set. Thanks again for your awesome blog!

aix said...

cool :)

date command said...

I was searching for how to synchronize date and time and found your blog. I will try these steps and let you know.

Unknown said...

If the day of week is Friday, my date should be moved to next monday.. How can I get this

Unknown said...

I know its very basic question only. Hope u guys help me this one. watz the command to check time and date??

Unknown said...

Am a learner here. Could u please tel me how to check the size of the file???

Olivier said...

127.127.1.0 ?? shouldn't that be 127.0.0.1 ?

aix said...

Hi, I used this IBM page as a source fpr that part: http://www-01.ibm.com/support/docview.wss?uid=isg3T1000653

Anonymous said...

This is from the redbook : The 127.127.1.0 address is a special address that tells the AIX server to
synchronize to its own system clock. Of course, a computer with a decent
clock that does not “wander” much should be chosen as the private primary
NTP server

aix said...

Thx, good info!

DHINESH EVERGREEN said...

date

Anonymous said...

Hi, Can you tell if there is a way to have the change in time logged by syslogd ? i tried daemon.info in syslog.conf but it does not work.

thanks.
regards, Tom

Unknown said...

Hi All,

We received lot of security issues with NTP. Please confirm in /etc/ntp.conf if below setting should be fine.

restrict default nomask 0.0.0.0 nopeer nomodify notrap noquery
restrict 127.0.0.1
server abc1.xyz.net prefer
server abc2.xyz.net
broadcastclient
driftfile /etc/ntp.drift
tracefile /etc/ntp.trace

Anonymous said...

instead of editing a file /etс/rс.tсpip, you can use the following command # chssys -s xntpd -a '-x'

santosh said...

Hi Team,

Is it possible to "input date" output to "date command". I want to convert some older dates to Coordinated Universal Time.

Kindly help.

Best Regards,
Santosh.

Unknown said...

Hi,

I need to Update NTP to latest version, at least 4.2.8p7 or 4.3.92 on AIX 6.1. current version of NTP is 4.2.4.

kindly guide how to update version. from where to download. complete steps.


Br,

santosh said...

How to restrict mode 6 query in AIX 7?

Ramdas said...

does it require reboot to have TZ in effect ?

Anonymous said...

I need to update the timezone data for America/Sao_Paulo on an AIX 6.1, but the file does not exist. What is the secret?

root@xxx:/usr/share/lib/zoneinfo> echo $TZ
America/Sao_Paulo

root@xxx:/usr/share/lib/zoneinfo> ls
Australia CST6CDT EET GB-Eire GMT+10 GMT+13 GMT+4 GMT+7 GMT-1 GMT-12 GMT-4 GMT-7 Greenwich Iceland MET Mexico Navajo Poland Turkey UTC WET
Brazil Canada EST GMT GMT+11 GMT+2 GMT+5 GMT+8 GMT-10 GMT-2 GMT-5 GMT-8 HST Israel MST NZ PRC ROC UCT Universal
CET Chile EST5EDT GMT+1 GMT+12 GMT+3 GMT+6 GMT+9 GMT-11 GMT-3 GMT-6 GMT-9 Hongkong Japan MST7MDT NZ-CHAT PST8PDT Singapore US W-SU