Home > AS/400 Tips > iSeries administrator tips > Set your system time using FTP
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES ADMINISTRATOR TIPS

Set your system time using FTP


Doug Hart
05.16.2002
Rating: -4.54- (out of 5) Hall of fame tip of the month winner


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


My client has seven iSeries systems, and the time is set by hand on each. This causes a swing of several minutes from the slowest to the fastest. A number of good tools exist that use time protocols to get the correct time from the Internet or perhaps even the more accurate GPS system. Most are written in 'C' and/or use sockets programming. These methods use several protocols NTP(SNTP) port 123, DAYTIME port 13, and TIME port 37.

My problem was that the client's network management group has these ports blocked at the firewall (and not FTP "go figure" ). So with some investigation, I found that by FTP-ing into the U.S. Navy time server I would get a welcome message containing the Coordinated Universal Time (UTC) time. Now this method has more overhead than standard SNTP and the accuracy will suffer. On my oldest and slowest system I find the time to be 5 to 8 seconds slow, but this is still far better than manually setting the clock.

The setup is quite simple. First create a dummy file for the compile requirement.

 CRTPF FILE(QTEMP/FTPLOG) RCDLEN(132)

You will also need to create a source physical file named FTPTIME. Add to this file (using SEU) a TXT member named FTP. These two lines will log you into the FTP server. Edit the member adding these two lines:
anonymous your@email.com
quit

Now compile this CLP interactively with enough authority to change the sysval QTIME. Note: The line "DCL VAR(&UPDATE) TYPE(*LGL) VALUE('0')" must be changed to ('1') for the system value to be changed.

CL Program FTPTIME

/********************************************************************+
|                                                                    +
|  FTP to my FTP server and capture the login text which contains    +
|  the current UTC time.  Then set the system time.                  +
|                                                                    +
|  Note: Job must run with authority that can CHGSYSVAL QTIME        +
|        This program requires you correctly set the SYSVAL          +
|        QUTCOFFSET for your time zone.                              +
|  Tip: Using your browser go to www.time.gov for your time zone     +
|        offset value (US ONLY).  International users may want to    +
|        use www.worldtimeserver.com and use the left side bar.      +
|                                                                    +
|  Doug Hart  1/31/2002                                              +
|                                                                    +
+*********************************************************************/

             PGM

/*********************************************************************/
/* Local Variables                                                   */
/*********************************************************************/

                    /* Switch 0=no update, 1=update */
             DCL        VAR(&UPDATE) TYPE(*LGL) VALUE('0')
 
             DCL        VAR(&TGTSYS) TYPE(*CHAR) LEN(30) +
                          VALUE('dhart.no-ip.info') /* My FTP Server */
             DCL        VAR(&CMPSTR) TYPE(*CHAR) LEN(5) +
                          VALUE('220-Q') /* line compare string */   

             DCL        VAR(&UTCSYSVAL) TYPE(*CHAR) LEN(5)
             DCL        VAR(&UTC) TYPE(*DEC) LEN(2 0)
             DCL        VAR(&UTCSIGN) TYPE(*CHAR) LEN(1)
             DCL        VAR(&HH) TYPE(*CHAR) LEN(2)
             DCL        VAR(&MM) TYPE(*CHAR) LEN(2)
             DCL        VAR(&SS) TYPE(*CHAR) LEN(2)
             DCL        VAR(&HHN) TYPE(*DEC) LEN(2 0)
             DCL        VAR(&TIME) TYPE(*CHAR) LEN(6)
             DCL        VAR(&QTIME) TYPE(*CHAR) LEN(6)
/********************************************************************/
/*     Setup variables for QCLSCAN program                          */
/********************************************************************/
             DCL        VAR(&STRING) TYPE(*CHAR) LEN(132)
             DCL        VAR(&STRLEN) TYPE(*DEC) LEN(3 0) VALUE(132)
             DCL        VAR(&STRPOS) TYPE(*DEC) LEN(3 0) VALUE(25)
             DCL        VAR(&PATTERN) TYPE(*CHAR) LEN(1) +
                          VALUE(':')
             DCL        VAR(&PATLEN) TYPE(*DEC) LEN(3 0) VALUE(1)
             DCL        VAR(&TRANSLATE) TYPE(*CHAR) LEN(1) VALUE('0')
             DCL        VAR(&TRIM) TYPE(*CHAR) LEN(1) VALUE('0')
             DCL        VAR(&WILD) TYPE(*CHAR) LEN(1) VALUE(' ')
             DCL        VAR(&RESULT) TYPE(*DEC) LEN(3 0) VALUE(1)
/********************************************************************/
/*     File in QTEMP that will be parsed for time string            */
/*     To compile program, file must be created and in libl         */
/********************************************************************/
             DCLF       FILE(FTPLOG)
/********************************************************************/
/* Get UTC time offset hours and + or - sign from sysval            */
/********************************************************************/
             RTVSYSVAL  SYSVAL(QUTCOFFSET) RTNVAR(&UTCSYSVAL)
             CHGVAR     VAR(&UTCSIGN) VALUE(%SST(&UTCSYSVAL 1 1))
             CHGVAR     VAR(&UTC) VALUE(%SST(&UTCSYSVAL 2 2))
/********************************************************************/
/* Build the FTP login file.                                        */
/*   This file has only two records holding the password and email  */
/*   and the FTP command QUIT needed for the Navy FTP server.       */
/*   ex:  ANONYMOUS                             */
/*        QUIT                                                      */
/*   Note: This can be setup once manually using SEU                */
/********************************************************************/
        /*   CRTSRCPF   FILE(*LIBL/FTPTIME) RCDLEN(140) MBR(FTP) */
/********************************************************************/
/* Delete/Create the FTP transfer log file                          */
/********************************************************************/
             DLTF       FILE(QTEMP/FTPLOG)
             MONMSG     MSGID(CPF0000)
             CRTPF      FILE(QTEMP/FTPLOG) RCDLEN(132) MBR(FTPLOG)
/********************************************************************/
/* Execute FTP transfer                                             */
/********************************************************************/
             OVRDBF     FILE(INPUT) TOFILE(*LIBL/FTPTIME) MBR(FTP)
             OVRDBF     FILE(OUTPUT) TOFILE(QTEMP/FTPLOG) MBR(FTPLOG)
             STRTCPFTP  RMTSYS(&TGTSYS)
             DLTOVR     FILE(*ALL)
/********************************************************************/
/* Parse FTPLOG file for time string                                */
/********************************************************************/
 READ:       RCVF
             MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(END))
             /* End of file found and record not found = error */

             IF         COND(%SST(&FTPLOG 1 5) = &CMPSTR) THEN(DO) +
/********************************************************************/
/* Found time string line in log starting with "220-Q"              */
/* Now parse the line for ':' to get time position                  */
/* Then convert the string to HH MM SS values                       */
/********************************************************************/

             CHGVAR     VAR(&STRING) VALUE(&FTPLOG)
             CALL       PGM(QCLSCAN) PARM(&STRING &STRLEN &STRPOS +
                          &PATTERN &PATLEN &TRANSLATE &TRIM &WILD +
                          &RESULT)
             IF         COND(&RESULT = 0) THEN(GOTO CMDLBL(END))
             /* Time ':' not found in string = error */

             CHGVAR     VAR(&RESULT) VALUE(&RESULT - 2)
             CHGVAR     VAR(&HH) VALUE(%SST(&FTPLOG &RESULT 2))
             CHGVAR     VAR(&RESULT) VALUE(&RESULT + 3)
             CHGVAR     VAR(&MM) VALUE(%SST(&FTPLOG &RESULT 2))
             CHGVAR     VAR(&RESULT) VALUE(&RESULT + 3)
             CHGVAR     VAR(&SS) VALUE(%SST(&FTPLOG &RESULT 2))


/********************************************************************/
/* Adjust to your time zone                                         */
/********************************************************************/
             CHGVAR     VAR(&HHN) VALUE(&HH)

             IF         COND(&UTCSIGN = '-') THEN(DO)
             CHGVAR     VAR(&HHN) VALUE(&HHN - &UTC)
             IF         COND(&HHN < 0) THEN(CHGVAR VAR(&HHN) +
                          VALUE(24 + &HHN))
             ENDDO
             ELSE       CMD(DO) /* &UTCSIGN = '+' */
             CHGVAR     VAR(&HHN) VALUE(&HHN + &UTC)
             IF         COND(&HHN > 23) THEN(CHGVAR VAR(&HHN) +
                          VALUE(&HHN - 24))
             ENDDO

             CHGVAR     VAR(&HH) VALUE(&HHN)

/********************************************************************/
/* Set the system value QTIME                                       */
/********************************************************************/
             CHGVAR     VAR(&TIME) VALUE(&HH || &MM || &SS)
             RTVSYSVAL  SYSVAL(QTIME) RTNVAR(&QTIME)
             IF         COND(&UPDATE) +
               THEN(CHGSYSVAL  SYSVAL(QTIME) VALUE(&TIME))
             SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('System +
                          time changed from' |> %SST(&QTIME 1 2) || +
                          ':' || %SST(&QTIME 3 2) || ':' || +
                          %SST(&QTIME 5 2) |> 'to' |> &HH || ':' || +
                          &MM || ':' || &SS |> 'by FTPTIME +
                          program') MSGTYPE(*INFO)

             RETURN     /* Good completion */
             ENDDO

             GOTO       CMDLBL(READ) /* get next record loop */

/********************************************************************/
/* On error send mesage                                             */
/********************************************************************/
 END:        SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('FTP +
                          time process ended in ERROR.  Check +
                          joblog for details, or review the QTEMP +
                          files FTPCMD and FTPLOG.') MSGTYPE(*ESCAPE)

             ENDPGM

If you wish to automate the Daylight saving time adjustment of your sysval QUTCOFFSET use this 2nd small CLP. Note: the values are for the East coast U.S. only, change them as needed for your location (see red). This program can be setup in any basic job scheduler to run every Sunday at 2:00.

Daylight saving time starts the 1st Sunday in April at 2 a.m. It ends the last Sunday in October at 2 a.m. (These are U.S. rules.)

CL Program ADJUTC


/* ----------------------------------------------------------------- +
 |  Program: ADJUTC Adjust UTC Sysval                                +
 |  Date   : 2/05/2002                                               +
 |  Author : D. Hart                                                 +
 |                                                                   +
 |  Function: Adjust for Daylight Saving Time the system value       +
 |            QUTCOFFSET.  This is only for the Eastern US time zone +
 |            Run this job every Sunday at 02:00 in system job       +
 |            scheduler.                                             +
 |  Tip: see http://webexhibits.org/daylightsaving/b.html for more.  + 
 |                                                                   +
 |  Coordinated Universal Time -4 hours; Daylight Saving Time        +
 |  Coordinated Universal Time -5 hours; Eastern Standard Time       +
 |                                                                   +
 L ----------------------------------------------------------------- */

             PGM

             DCL        VAR(&DAYOFWEEK) TYPE(*CHAR) LEN(4)     
             DCL        VAR(&MONTH) TYPE(*CHAR) LEN(2)
             DCL        VAR(&DAY) TYPE(*CHAR) LEN(2)

             /* Ensure that this is a Sunday */              
             RTVSYSVAL  SYSVAL(QDAYOFWEEK) RTNVAR(&DAYOFWEEK)
             IF         COND(&DAYOFWEEK *EQ '*SUN') THEN(DO) 

               RTVSYSVAL  SYSVAL(QMONTH) RTNVAR(&MONTH)
               RTVSYSVAL  SYSVAL(QDAY) RTNVAR(&DAY)

               /* 1ST Sunday in April start Daylight Saving Time */
               IF         COND(&MONTH = '04' *AND &DAY *LE '07') THEN( +
                  CHGSYSVAL SYSVAL(QUTCOFFSET) VALUE('-0400'))

               /* Last Sunday in October end Daylight Saving Time */
               IF         COND(&MONTH = '10' *AND &DAY *GE '25') THEN( +
                  CHGSYSVAL SYSVAL(QUTCOFFSET) VALUE('-0500'))
             
             ENDDO
          
             ENDPGM

Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
iSeries administrator tips
Analyze the health of your IBM i server with iScore
Researching high availability for your System i shop
Translating Linux for IBM i admins: Using GUI to make it easy
Translating Linux for IBM i admins: Working with jobs and networking
OpenOffice: What to know before making the transition from Microsoft Office
OpenOffice: An enterprise open source solution
Database performance comparisons on IBM i
Translating Linux for IBM i admins: User profile commands
Modern System i reports using Client Access
Tips for installing Lotus Domino server on a System i partition

Systems Management
Can you trust all those trigger programs?
Are your backups complete?
Controlling remote command processing
Watch your profiles
Avoid locking issues
Send message to users at a remote site
Security journal receiver management
Top 10 backup commands
Create an iSeries Access image and update it with the latest Service Pack
Tracking critical file access in real time

FTP
How to view source files in the library
Simplify the process of converting a spool file from iSeries into an Excel spreadsheet
Generically send a text file from the IFS via FTP
Automate Client Access to find files on Windows scheduler
SAVF by FTP on AS/400 -- error "source file not found"
Use a virtual directory to move a .bmp file from the IFS to a remote server
Transferring binary files to IFS from a PC via FTP
FTP from AS/400 to PC folder
How to FTP without knowing the file name
IFS folder error

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts