Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date: illegal option -- j (Mac OS X 10.4.11) #497

Open
etanol85 opened this issue Feb 6, 2020 · 4 comments
Open

date: illegal option -- j (Mac OS X 10.4.11) #497

etanol85 opened this issue Feb 6, 2020 · 4 comments
Assignees

Comments

@etanol85
Copy link

etanol85 commented Feb 6, 2020

When running getssl mydomain.com under MAC OS 10.4.11

I see the folowing error:
usage: date [-nu] [-r seconds] [+format]
date [[[[[cc]yy]mm]dd]hh]mm[.ss]

The script seems to continue despite this error but I don’t know if it works correctly.

man date gives:
DATE(1) BSD General Commands Manual DATE(1)

NAME
date -- display or set date and time

SYNOPSIS
date [-nu] [-r seconds] [+format]
date [-u] mmddhhmm[[cc]yy]

DESCRIPTION
date displays the current date and time when invoked without arguments.
Providing arguments will format the date and time in a user-defined way
or set the date. Only the superuser may set the date.

 The options are as follows:

 -n      The utility timed(8) is used to synchronize the clocks on groups
         of machines.  By default, if timed is running, date will set the
         time on all of the machines in the local group.  The -n option
         stops date from setting the time for other than the current
         machine.

 -r      Print out the date and time that is seconds from the Epoch.

 -u      Display or set the date in UTC (universal) time.
 An operand with a leading plus (``+'') sign signals a user-defined format
 string which specifies the format in which to display the date and time.
 The format string may contain any of the conversion specifications
 described in the strftime(3) manual page, as well as any arbitrary text.
 A <newline> character is always output after the characters specified by
 the format string.  The format string for the default display is:

       ``%a %b %e %H:%M:%S %Z %Y''.

 If an operand does not have a leading plus sign, it is interpreted as a
 value for setting the system's notion of the current date and time.  The
 canonical representation for setting the date and time is:

       cc      The first two digits of the year (the century).
       yy      The second two digits of the year.  If ``yy'' is specified,
               but ``cc'' is not, a value for ``yy'' between 69 and 99
               results in a ``cc'' value of 19.  Otherwise, a ``cc'' value
               of 20 is used.
       mm      The month of the year, from 1 to 12.
       dd      The day of the month, from 1 to 31.
       hh      The hour of the day, from 0 to 23.
       mm      The minute of the hour, from 0 to 59.
       ss      The second of the minute, from 0 to 61.

 Everything but the minutes is optional.

 Time changes for Daylight Saving and Standard time and leap seconds and
 years are handled automatically.

ENVIRONMENT VARIABLES
The following environment variables affect the execution of date :

 TZ  The timezone to use when displaying dates.  See environ(7) for more
     information.

FILES
/var/log/wtmp A record of date resets and time changes.
/var/log/messages A record of the user setting the time.

EXAMPLES
The command:

       date "+DATE: %m/%d/%y%nTIME: %H:%M:%S"

 will display:

       DATE: 11/21/87
       TIME: 13:36:16

 The command:

       date 061316271985

 sets the date to ``June 13, 1985, 4:27 PM''.

 The command:

       date 1432

 sets the time to 2:32 PM, without modifying the date.

DIAGNOSTICS
The following exit values are returned:
0 The date was written successfully (either locally or globally)
DIAGNOSTICS
The following exit values are returned:
0 The date was written successfully (either locally or globally)
>0 An error occurred.

 Occasionally, when timed(8) synchronizes the time on many hosts, the set-
 ting of a new time value may require more than a few seconds.  On these
 occasions, date prints: `Network time being set'.  The message
 `Communication error with timed' occurs when the communication between
 date and timed fails.

LEGACY SYNOPSIS
date [-nu] [-r seconds] [+format]

      [[[[[cc]yy]mm]dd]hh]mm[.ss]

LEGACY DIAGNOSTICS
When invoked in legacy mode the following exit values are returned:
0 The date was written successfully
1 Unable to set the date
2 Able to set the local date, but unable to set it globally

SEE ALSO
gettimeofday(2), strftime(3), compat(5), utmp(5), timed(8)

 R. Gusella and S. Zatti, TSP: The Time Synchronization Protocol for UNIX
 4.3BSD.

STANDARDS
The date utility supports the Version 3 of the Single UNIX Specification
(SUSv3''). It is also expected to be compatible with IEEE Std 1003.2 (POSIX.2'').

BSD September 22, 2004 BSD
(END)

@timkimber
Copy link
Member

Hi @etanol85

It's a benign error as that piece of code just checks whether the certificate needs renewing, when it fails the code just renews the certificate.

I've spent some time researching this and the date command on MAC OS 10.4.11 doesn't support what we need and without any way I can test I'm reluctant to try and use an alternative command.

@rdebath
Copy link
Contributor

rdebath commented Feb 8, 2020

You may be interested in this ...

I use this awk program to mess with date ranges in my certificate script rather than trying to get date to work nicely everywhere. It works for Gregorian calendar dates from year one up on any awk derived from the '88 nawk version (basically all of them).

This gives "TODAY"
$ jdayjdat $(date '+%d %m %Y')
This gives "end date"
$ jdayjdat $(openssl x509 -noout -enddate -in cert.pem | sed 's/^[^=]*=https://' | awk '{print $2,$1,$4;}')

#!/bin/sh -

jdayjdat() {
    awk '#!/usr/bin/awk -f

    BEGIN{
	days[0] = "Sunday";
	days[1] = "Monday";
	days[2] = "Tuesday";
	days[3] = "Wednesday";
	days[4] = "Thursday";
	days[5] = "Friday";
	days[6] = "Saturday";

	months["jan"] = 1;
	months["feb"] = 2;
	months["mar"] = 3;
	months["apr"] = 4;
	months["may"] = 5;
	months["jun"] = 6;
	months["jul"] = 7;
	months["aug"] = 8;
	months["sep"] = 9;
	months["oct"] = 10;
	months["nov"] = 11;
	months["dec"] = 12;

	if(ARGC == 2) {
	    j = ARGV[1]+0;
	    if (j>0 && j<65536) j += 2400000
	    split(jdate(j),A);
	    print A[1];
	} else if(ARGC >= 4) {
	    d = ARGV[1]; m = ARGV[2]; y = ARGV[3];

	    if (d+0 > 999 && y < 100) { ms = d; d = y; y = ms; }
	    ms = tolower(substr(m, 1, 3));
	    if (ms in months) m = months[ms];
	    else {
		ms = tolower(substr(d, 1, 3));
		if (ms in months) {
		    d = m;
		    m = months[ms];
		}
	    }

	    if( y>31 && y<70 ) y+=2000;
	    if( y>31 && y<100) y+=1900;
	    if( m<1)  {m+=12; y--;}
	    if( m>12) {m-=12; y++;}

	    jd = jday(d,m,y);
	    if (ARGC > 4) {
		printf("Input: %04d-%02d-%02d\n", y, m, d);
		print jd
		js = jdate(jd);
		split(js,A,/[- ]/);
		print js;
		print A[1], A[2], A[3], days[A[4]];
	    } else
		print jd
	} else
	    print "Incorrect arguments"
    }

    function jdate(j,  y,m,d,dow)
    {
	# Julian date converter. Takes a julian date (the number of days since
	# some distant epoch or other) and returns the broken out date.
	# d = day of month;
	# m = month;
	# y = year (actual year, like 1977, not 77 unless it was  77 a.d.);
	# dow = day of week (0->Sunday to 6->Saturday)
	# These are Gregorian.
	# Copied from Algorithm 199 in Collected algorithms of the CACM
	# Author: Robert G. Tantzen, Translators: Nat Howard, Robert de Bath

	j = j + 1
	dow = (j + 1)%7;
	j -= 1721119;
	# This should be a Euclidean division. But dates before 0001-01-01 dont
	# make much sense anyway. Or even Friday, 15 October 1582 when the
	# Gregorian calendar started.
	y = int((4 * j - 1)/146097);
	j = 4 * j - 1 - 146097 * y;
	d = int(j/4);
	j = int((4 * d + 3)/1461);
	d = 4 * d + 3 - 1461 * j;
	d = int((d + 4)/4);
	m = int((5 * d - 3)/153);
	d = 5 * d - 3 - 153 * m;
	d = int((d + 5) / 5);
	y = 100 * y + j;
	if(m < 10) m += 3; else { m -= 9; ++y; }

	return sprintf("%04d-%02d-%02d %d", y, m, d, dow);
    }

    function jday(d,m,y,  c,ya,j)
    {
	# Takes a date, and returns a Julian day. A Julian day is the number of
	# days since some base date  (in the very distant past).
	# Handy for getting date of x number of days after a given Julian date
	# (use jdate to get that from the Gregorian date).
	# Author: Robert G. Tantzen, translators: Nat Howard, Robert de Bath
	# Translated from the algol original in Collected Algorithms of CACM
	# (This and jdate are algorithm 199).

	if(m>2) m -=3; else { m +=9; --y; }
	c = int(y/100);
	ya = y - (100*c);
	j = int(146097*c/4) + int(1461*ya/4) + int((153*m+2)/5) + d + 1721119;

	return j - 1;
    }
    ' "$@"
}

jdayjdat "$@"

@timkimber timkimber self-assigned this Feb 11, 2020
@etanol85
Copy link
Author

Thank you timkimber and rdebath!

I just tried rdebath jdayjdat awk script, but it seems not to display the date correctly. When I ran jdayjdat $(date ’+%d %m %Y’) it prints 2459026 and today it is 26-06-2020, date gives: Fri Jun 26 09:02:29 CEST 2020

Am I missing something?

@timkimber
Copy link
Member

Hi @etanol85

I found out recently that github actions support MacOS so I'll write a test for this scenario and post an update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants