This is a discussion on Getting "date" command to output the date in milli-seconds - Possible or not? within the AIX Operating System forums, part of the Unix Operating Systems category; --> Can anyone tell me if it is possible to get the AIX "date" command to output the current time ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Can anyone tell me if it is possible to get the AIX "date" command to output the current time down to milli-seconds. A review of the man pages shows how to output time only as accurately as seconds. I need this to log the start time of a regularly called script. This script functions properly only when ran as single instance. I had problems with a remote host calling this twice within a second of each other. Some kind of scheduler hiccup on the calling side. I have implemented a lock file locking mechanism to stop this happening in the future, but I would like to be able to log the start time of my script down to milli-seconds for logging purposes, and to aid in finding out why the remote host (an Oracle ERP host) experiences a double call sometimes. If the "date" command is not this accurate, can anyone suggest alternatives? Thanks in advance! Tom. |
| |||
| Hello, TOM, have you tried the cycle in the script once you have started it it will continue run after the cycle perioud with the best BRIEDIS "Tom Brehony" <tombrehony.nospam@eircom.nospam.net> wrote in message news:<2m4a8lFihmcrU1@uni-berlin.de>... > Can anyone tell me if it is possible to get the AIX "date" command to output > the > current time down to milli-seconds. A review of the man pages shows how to > output time only as accurately as seconds. > > I need this to log the start time of a regularly called script. This script > functions > properly only when ran as single instance. I had problems with a remote host > calling this twice within a second of each other. Some kind of scheduler > hiccup > on the calling side. > > I have implemented a lock file locking mechanism to stop this happening in > the > future, but I would like to be able to log the start time of my script down > to > milli-seconds for logging purposes, and to aid in finding out why the remote > host (an Oracle ERP host) experiences a double call sometimes. > > If the "date" command is not this accurate, can anyone suggest alternatives? > Thanks in advance! > > Tom. |
| |||
| Janis, I am sorry but I do not understand what you are saying here. What do you mean "the cycle in the script"? Tom. "janis.briedis" <janis.briedis@tl.lv> wrote in message news:b06898f5.0407200640.14d623a7@posting.google.c om... > Hello, TOM, > > have you tried the cycle in the script > once you have started it it will continue run after the cycle perioud > > > with the best > BRIEDIS > > "Tom Brehony" <tombrehony.nospam@eircom.nospam.net> wrote in message news:<2m4a8lFihmcrU1@uni-berlin.de>... > > Can anyone tell me if it is possible to get the AIX "date" command to output > > the > > current time down to milli-seconds. A review of the man pages shows how to > > output time only as accurately as seconds. > > > > I need this to log the start time of a regularly called script. This script > > functions > > properly only when ran as single instance. I had problems with a remote host > > calling this twice within a second of each other. Some kind of scheduler > > hiccup > > on the calling side. > > > > I have implemented a lock file locking mechanism to stop this happening in > > the > > future, but I would like to be able to log the start time of my script down > > to > > milli-seconds for logging purposes, and to aid in finding out why the remote > > host (an Oracle ERP host) experiences a double call sometimes. > > > > If the "date" command is not this accurate, can anyone suggest alternatives? > > Thanks in advance! > > > > Tom. |
| |||
| "Tom Brehony" <tombrehony.nospam@eircom.nospam.net> writes: >Can anyone tell me if it is possible to get the AIX "date" command to output >the current time down to milli-seconds. A review of the man pages shows >how to output time only as accurately as seconds. I believe the answer is "no". However, here is a quick and dirty C program you can use for that purpose: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <time.h> #include <sys/time.h> int main(int argc, char **argv) { struct timeval tv; struct tm *tm; char *ofmt; char *nfmt; char *osp, *nsp; char buf[1024]; if (argc != 2) { fprintf(stderr, "Usage: %s format\n", argv[0]); exit(1); } ofmt = argv[1]; if (gettimeofday(&tv, NULL) < 0 ) { perror("gettimeofday"); exit(1); } tm = localtime(&tv.tv_sec); nfmt = malloc(strlen(ofmt) * 6 / 2 + 100); if (nfmt == NULL) { perror("malloc new fmt"); exit(2); } /* * Locate %s sequences and replace with microseconds */ nfmt[0] = '\0'; nsp = nfmt; while ((osp = strstr(ofmt, "%s")) != NULL) { size_t l; l = osp - ofmt; strncpy(nsp, ofmt, l); sprintf(nsp+l, "%06d", tv.tv_usec ); ofmt = osp+2; nsp += strlen(nsp); } strcpy(nsp, ofmt); if (strftime(buf, sizeof(buf), nfmt, tm) == 0) { perror("strftime"); exit(2); } puts(buf); return 0; } Call it with a single argument, which is a format as accepted by strftime(), augmented by the formst %s, which gives you 6 digits of microseconds. Thus, to show the current date and time with microseconds, use ./a.out %Y-%m-%d,%H:%M:%S.%s 2004-07-20,13:31:41.788645 >I have implemented a lock file locking mechanism to stop this happening in >the future, but I would like to be able to log the start time of my script >down to milli-seconds for logging purposes, and to aid in finding out why >the remote host (an Oracle ERP host) experiences a double call sometimes. Is it possible you are seeing the previous instance of the call getting hung up, until the next instance somehow shakes it loose, and the two then run at the same time? -- Dale Talcott, IT Research Computing Services, Purdue University aeh@quest.cc.purdue.edu http://quest.cc.purdue.edu/~aeh/ |
| ||||
| Excellent Dale, it's perfect! Many thanks. Tom. "Dale Talcott" <aeh@quest.cc.purdue.edu> wrote in message news:aeh.1090348515@quest.cc.purdue.edu... > "Tom Brehony" <tombrehony.nospam@eircom.nospam.net> writes: > > >Can anyone tell me if it is possible to get the AIX "date" command to output > >the current time down to milli-seconds. A review of the man pages shows > >how to output time only as accurately as seconds. > > I believe the answer is "no". However, here is a quick and dirty C program > you can use for that purpose: > > #include <stdio.h> > #include <stdlib.h> > #include <unistd.h> > #include <string.h> > #include <time.h> > #include <sys/time.h> > > int main(int argc, char **argv) > { > struct timeval tv; > struct tm *tm; > char *ofmt; > char *nfmt; > char *osp, *nsp; > char buf[1024]; > > if (argc != 2) { > fprintf(stderr, "Usage: %s format\n", argv[0]); > exit(1); > } > ofmt = argv[1]; > > if (gettimeofday(&tv, NULL) < 0 ) { > perror("gettimeofday"); > exit(1); > } > tm = localtime(&tv.tv_sec); > nfmt = malloc(strlen(ofmt) * 6 / 2 + 100); > if (nfmt == NULL) { > perror("malloc new fmt"); > exit(2); > } > /* > * Locate %s sequences and replace with microseconds > */ > nfmt[0] = '\0'; > nsp = nfmt; > while ((osp = strstr(ofmt, "%s")) != NULL) { > size_t l; > l = osp - ofmt; > strncpy(nsp, ofmt, l); > sprintf(nsp+l, "%06d", tv.tv_usec ); > ofmt = osp+2; > nsp += strlen(nsp); > } > strcpy(nsp, ofmt); > if (strftime(buf, sizeof(buf), nfmt, tm) == 0) { > perror("strftime"); > exit(2); > } > puts(buf); > > return 0; > } > > Call it with a single argument, which is a format as accepted by > strftime(), augmented by the formst %s, which gives you 6 digits > of microseconds. Thus, to show the current date and time with > microseconds, use > > ./a.out %Y-%m-%d,%H:%M:%S.%s > 2004-07-20,13:31:41.788645 > > >I have implemented a lock file locking mechanism to stop this happening in > >the future, but I would like to be able to log the start time of my script > >down to milli-seconds for logging purposes, and to aid in finding out why > >the remote host (an Oracle ERP host) experiences a double call sometimes. > > Is it possible you are seeing the previous instance of the call getting > hung up, until the next instance somehow shakes it loose, and the two > then run at the same time? > > -- > Dale Talcott, IT Research Computing Services, Purdue University > aeh@quest.cc.purdue.edu http://quest.cc.purdue.edu/~aeh/ |