Re: [sage-devel] Please check if this computes seconds since Epoch
John Cremona wrote: I must admit I'm puzzled it needed the .sh on the end. Are you sure you had the execute permission on the version without the .sh ? Yes, definitely. (If not, even ./unixtime.sh would have failed.) Fair enough. I don't know much about dash, but I know if you proceed the name of a script by 'sh', the script will execute even if it has no execute permissions. bash-3.2$ ls -l testcc.sh -rw-r--r-- 1 drkirkby staff 4781 Dec 8 16:35 testcc.sh bash-3.2$ sh testcc.sh GCC bash-3.2$ Anyway, it does not matter when the code is added to determine seconds since the Epoch, since the top of $SAGE_ROOT/spkg/install has #!/usr/bin/env bash In this case, the code will be run with bash - irrespective of what shell you use. I'm still puzzled though I must admit, why it says No such file or directory, since the file clearly exists. I suppose I have never used the 'dash' shell, so don't know how it behaves. Nor me. But someone will try to build Sage with it one day! Very true. It's useful to get these things checked on many shells. John Thanks John. Dave -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org
Re: [sage-devel] Please check if this computes seconds since Epoch
On Sun, Dec 13, 2009 at 11:01 PM, Peter Jeremy peterjer...@acm.org wrote: On 2009-Dec-13 16:27:41 +, Dr. David Kirkby david.kir...@onetel.net wrote: If you have a system with the GNU version of date, then date -u +%s will give the seconds since the Epoch. Unfortunately, it only works with GNU date, and so will not work on Solaris, HP-UX or no doubt many other Unix systems. FWIW, '%s' _does_ work with FreeBSD. It works with OS X also. For every system I am able to check this on, the following script gives exactly the same output as the GNU date command, but in a more portable manner. It works on FreeBSD/amd64 and FreeBSD/i386. It probably needs some more rigorous checking than it works today. Where did you find this particular algorithm - it's somewhat simpler than the one I use. # $5 = seconds (0-59) Whilst we're being pedantic, this should be (0..60) to allow for leap seconds. On 2009-Dec-13 17:05:25 +, Dr. David Kirkby david.kir...@onetel.net wrote: The code takes leap years into account, and is said to work until 2100, in which case, we will all be dead. (or 2034 unless unix time is changed to a 64-bit number). A few comments: - The 32-bit Unix epoch rolls over in 2038. - This also depends on the type expr(1) uses for integer math. - I wouldn't bet on everyone currently working on Sage being dead in 2100: If you're in your early 20's now, you'll be less that 115 then - which is not impossible today and will only become more common in future (assuming advances in medical science continue and aren't offset by a worsening environment). Check out the latest addition here http://sagemath.org/library-stories.html in the upper right. It is from someone who is very interested in contributing to Sage... and he is 12 years old! William -- William Stein Associate Professor of Mathematics University of Washington http://wstein.org -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org
Re: [sage-devel] Please check if this computes seconds since Epoch
On a 64-bit ubuntu system I had to include the .sh like this: j...@selmer%date -u +%s ./unixtime.sh 1260823644 1260823644 since: j...@selmer%date -u +%s ./unixtime 1260823676 -bash: ./unixtime: No such file or directory My $SHELL is /bin/bash but your script uses /bin/sh which here is j...@selmer%ls -l /bin/sh lrwxrwxrwx 1 root root 4 2009-06-25 11:41 /bin/sh - dash dash? John 2009/12/13 Dr. David Kirkby david.kir...@onetel.net: If you have a system with the GNU version of date, then date -u +%s will give the seconds since the Epoch. Unfortunately, it only works with GNU date, and so will not work on Solaris, HP-UX or no doubt many other Unix systems. The following script should compute this is a portable manner. Here's a few examples On sage.math, where date accepts +%s kir...@sage:~$ date -u +%s ./unixtime 1260720556 1260720556 On an HP-UX system, where date does *not* accept +%s bash-2.04$ uname -a HP-UX hpbox B.11.11 U 9000/785 2016698240 unlimited-user license bash-2.04$ ./unixtime date -u +%s 1260720771 date: bad format character - s On an OpenSolaris system, where date does *not* accept +%s bash-3.2$ ./unixtime date -u +%s 1260720823 %s On an IBM server running AIX 6.1, where date does accept +%s $ uname -a AIX client1 1 6 00C6B7C04C00 $ ./unixtime date -u +%s 1260721013 1260721013 For every system I am able to check this on, the following script gives exactly the same output as the GNU date command, but in a more portable manner. Could a few people check it on their systems. If it does work, I'd propose it is used in place of the GNUism introduced in http://trac.sagemath.org/sage_trac/ticket/6744 Currently the file .BUILDSTART created by #6744 is not actually used anywhere in Sage, but clearly the intension is to use it at some point, in which case it will be found not to work on some systems. Dave --- #!/bin/sh # Compute seconds since the Epoch. # Call 'date'. Note that # %Y = year including century # %j = day number (1-365) # %H = hour (0-23) # %M = minute (0-59) # %S = seconds (0-59) if type env /dev/null 21 ; then set -- `env LC_ALL=C LC_TIME=C LANG=C date -u '+%Y %j %H %M %S'` else set -- `date -u '+%Y %j %H %M %S'` fi # $1 = year including century # $2 = day number (1-365) # $3 = hour (0-23) # $4 = minute (0-59) # $5 = seconds (0-59) if [ $? -ne 0 ] || [ $# -lt 5 ] ; then TIME=Error computing seconds since the Epoch fi DAYS=`expr 365 \* \( $1 - 1970 \) + \( $1 - 1969 \) / 4 + $2 - 1` TIME=`expr $5 + 60 \* \( $4 + 60 \* \( $3 + 24 \* $DAYS \) \)` echo $TIME -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org
Re: [sage-devel] Please check if this computes seconds since Epoch
John Cremona wrote: On a 64-bit ubuntu system I had to include the .sh like this: j...@selmer%date -u +%s ./unixtime.sh 1260823644 1260823644 since: j...@selmer%date -u +%s ./unixtime 1260823676 -bash: ./unixtime: No such file or directory My $SHELL is /bin/bash but your script uses /bin/sh which here is j...@selmer%ls -l /bin/sh lrwxrwxrwx 1 root root 4 2009-06-25 11:41 /bin/sh - dash dash? Thank you for that John, The code will actually go into the script $SAGE_ROOT/spkg/install which has at the top of it: #!/usr/bin/env bash echo `date -u +%s` .BUILDSTART So my code will actually be executed with 'bash'. I want to get rid of the GNU-specific option to the date command. I guess I should have put #!/usr/bin/env bash in the script I posted, but I tend only to write scripts that make use of things supported by a minimal /bin/sh, rather than rely on any bash-specific features. I must admit I'm puzzled it needed the .sh on the end. Are you sure you had the execute permission on the version without the .sh ? I'm still puzzled though I must admit, why it says No such file or directory, since the file clearly exists. I suppose I have never used the 'dash' shell, so don't know how it behaves. bash is considered a perquisite for Sage, though personally I tend to write thing that work with other shells. 'dash' seems pretty unique in not executing code without the .sh extension. The shells on Solaris, HP-UX, Linux, OS X and AIX all work without the .sh. So far, anyone that has posted the output and compared it with $ date +%s appears to give the same result, so I believe this will give us portability without compromising accuracy. Dave John 2009/12/13 Dr. David Kirkby david.kir...@onetel.net: If you have a system with the GNU version of date, then date -u +%s will give the seconds since the Epoch. Unfortunately, it only works with GNU date, and so will not work on Solaris, HP-UX or no doubt many other Unix systems. The following script should compute this is a portable manner. Here's a few examples On sage.math, where date accepts +%s kir...@sage:~$ date -u +%s ./unixtime 1260720556 1260720556 On an HP-UX system, where date does *not* accept +%s bash-2.04$ uname -a HP-UX hpbox B.11.11 U 9000/785 2016698240 unlimited-user license bash-2.04$ ./unixtime date -u +%s 1260720771 date: bad format character - s On an OpenSolaris system, where date does *not* accept +%s bash-3.2$ ./unixtime date -u +%s 1260720823 %s On an IBM server running AIX 6.1, where date does accept +%s $ uname -a AIX client1 1 6 00C6B7C04C00 $ ./unixtime date -u +%s 1260721013 1260721013 For every system I am able to check this on, the following script gives exactly the same output as the GNU date command, but in a more portable manner. Could a few people check it on their systems. If it does work, I'd propose it is used in place of the GNUism introduced in http://trac.sagemath.org/sage_trac/ticket/6744 Currently the file .BUILDSTART created by #6744 is not actually used anywhere in Sage, but clearly the intension is to use it at some point, in which case it will be found not to work on some systems. Dave --- #!/bin/sh # Compute seconds since the Epoch. # Call 'date'. Note that # %Y = year including century # %j = day number (1-365) # %H = hour (0-23) # %M = minute (0-59) # %S = seconds (0-59) if type env /dev/null 21 ; then set -- `env LC_ALL=C LC_TIME=C LANG=C date -u '+%Y %j %H %M %S'` else set -- `date -u '+%Y %j %H %M %S'` fi # $1 = year including century # $2 = day number (1-365) # $3 = hour (0-23) # $4 = minute (0-59) # $5 = seconds (0-59) if [ $? -ne 0 ] || [ $# -lt 5 ] ; then TIME=Error computing seconds since the Epoch fi DAYS=`expr 365 \* \( $1 - 1970 \) + \( $1 - 1969 \) / 4 + $2 - 1` TIME=`expr $5 + 60 \* \( $4 + 60 \* \( $3 + 24 \* $DAYS \) \)` echo $TIME -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org
Re: [sage-devel] Please check if this computes seconds since Epoch
2009/12/14 Dr. David Kirkby david.kir...@onetel.net: John Cremona wrote: On a 64-bit ubuntu system I had to include the .sh like this: j...@selmer%date -u +%s ./unixtime.sh 1260823644 1260823644 since: j...@selmer%date -u +%s ./unixtime 1260823676 -bash: ./unixtime: No such file or directory My $SHELL is /bin/bash but your script uses /bin/sh which here is j...@selmer%ls -l /bin/sh lrwxrwxrwx 1 root root 4 2009-06-25 11:41 /bin/sh - dash dash? Thank you for that John, The code will actually go into the script $SAGE_ROOT/spkg/install which has at the top of it: #!/usr/bin/env bash echo `date -u +%s` .BUILDSTART So my code will actually be executed with 'bash'. I want to get rid of the GNU-specific option to the date command. I guess I should have put #!/usr/bin/env bash in the script I posted, but I tend only to write scripts that make use of things supported by a minimal /bin/sh, rather than rely on any bash-specific features. I must admit I'm puzzled it needed the .sh on the end. Are you sure you had the execute permission on the version without the .sh ? Yes, definitely. (If not, even ./unixtime.sh would have failed.) I'm still puzzled though I must admit, why it says No such file or directory, since the file clearly exists. I suppose I have never used the 'dash' shell, so don't know how it behaves. Nor me. But someone will try to build Sage with it one day! John bash is considered a perquisite for Sage, though personally I tend to write thing that work with other shells. 'dash' seems pretty unique in not executing code without the .sh extension. The shells on Solaris, HP-UX, Linux, OS X and AIX all work without the .sh. So far, anyone that has posted the output and compared it with $ date +%s appears to give the same result, so I believe this will give us portability without compromising accuracy. Dave John 2009/12/13 Dr. David Kirkby david.kir...@onetel.net: If you have a system with the GNU version of date, then date -u +%s will give the seconds since the Epoch. Unfortunately, it only works with GNU date, and so will not work on Solaris, HP-UX or no doubt many other Unix systems. The following script should compute this is a portable manner. Here's a few examples On sage.math, where date accepts +%s kir...@sage:~$ date -u +%s ./unixtime 1260720556 1260720556 On an HP-UX system, where date does *not* accept +%s bash-2.04$ uname -a HP-UX hpbox B.11.11 U 9000/785 2016698240 unlimited-user license bash-2.04$ ./unixtime date -u +%s 1260720771 date: bad format character - s On an OpenSolaris system, where date does *not* accept +%s bash-3.2$ ./unixtime date -u +%s 1260720823 %s On an IBM server running AIX 6.1, where date does accept +%s $ uname -a AIX client1 1 6 00C6B7C04C00 $ ./unixtime date -u +%s 1260721013 1260721013 For every system I am able to check this on, the following script gives exactly the same output as the GNU date command, but in a more portable manner. Could a few people check it on their systems. If it does work, I'd propose it is used in place of the GNUism introduced in http://trac.sagemath.org/sage_trac/ticket/6744 Currently the file .BUILDSTART created by #6744 is not actually used anywhere in Sage, but clearly the intension is to use it at some point, in which case it will be found not to work on some systems. Dave --- #!/bin/sh # Compute seconds since the Epoch. # Call 'date'. Note that # %Y = year including century # %j = day number (1-365) # %H = hour (0-23) # %M = minute (0-59) # %S = seconds (0-59) if type env /dev/null 21 ; then set -- `env LC_ALL=C LC_TIME=C LANG=C date -u '+%Y %j %H %M %S'` else set -- `date -u '+%Y %j %H %M %S'` fi # $1 = year including century # $2 = day number (1-365) # $3 = hour (0-23) # $4 = minute (0-59) # $5 = seconds (0-59) if [ $? -ne 0 ] || [ $# -lt 5 ] ; then TIME=Error computing seconds since the Epoch fi DAYS=`expr 365 \* \( $1 - 1970 \) + \( $1 - 1969 \) / 4 + $2 - 1` TIME=`expr $5 + 60 \* \( $4 + 60 \* \( $3 + 24 \* $DAYS \) \)` echo $TIME -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at
[sage-devel] Please check if this computes seconds since Epoch
If you have a system with the GNU version of date, then date -u +%s will give the seconds since the Epoch. Unfortunately, it only works with GNU date, and so will not work on Solaris, HP-UX or no doubt many other Unix systems. The following script should compute this is a portable manner. Here's a few examples On sage.math, where date accepts +%s kir...@sage:~$ date -u +%s ./unixtime 1260720556 1260720556 On an HP-UX system, where date does *not* accept +%s bash-2.04$ uname -a HP-UX hpbox B.11.11 U 9000/785 2016698240 unlimited-user license bash-2.04$ ./unixtime date -u +%s 1260720771 date: bad format character - s On an OpenSolaris system, where date does *not* accept +%s bash-3.2$ ./unixtime date -u +%s 1260720823 %s On an IBM server running AIX 6.1, where date does accept +%s $ uname -a AIX client1 1 6 00C6B7C04C00 $ ./unixtime date -u +%s 1260721013 1260721013 For every system I am able to check this on, the following script gives exactly the same output as the GNU date command, but in a more portable manner. Could a few people check it on their systems. If it does work, I'd propose it is used in place of the GNUism introduced in http://trac.sagemath.org/sage_trac/ticket/6744 Currently the file .BUILDSTART created by #6744 is not actually used anywhere in Sage, but clearly the intension is to use it at some point, in which case it will be found not to work on some systems. Dave --- #!/bin/sh # Compute seconds since the Epoch. # Call 'date'. Note that # %Y = year including century # %j = day number (1-365) # %H = hour (0-23) # %M = minute (0-59) # %S = seconds (0-59) if type env /dev/null 21 ; then set -- `env LC_ALL=C LC_TIME=C LANG=C date -u '+%Y %j %H %M %S'` else set -- `date -u '+%Y %j %H %M %S'` fi # $1 = year including century # $2 = day number (1-365) # $3 = hour (0-23) # $4 = minute (0-59) # $5 = seconds (0-59) if [ $? -ne 0 ] || [ $# -lt 5 ] ; then TIME=Error computing seconds since the Epoch fi DAYS=`expr 365 \* \( $1 - 1970 \) + \( $1 - 1969 \) / 4 + $2 - 1` TIME=`expr $5 + 60 \* \( $4 + 60 \* \( $3 + 24 \* $DAYS \) \)` echo $TIME -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org
Re: [sage-devel] Please check if this computes seconds since Epoch
Dr. David Kirkby wrote: If you have a system with the GNU version of date, then date -u +%s will give the seconds since the Epoch. Unfortunately, it only works with GNU date, and so will not work on Solaris, HP-UX or no doubt many other Unix systems. The following script should compute this is a portable manner. Here's a few examples On sage.math, where date accepts +%s kir...@sage:~$ date -u +%s ./unixtime 1260720556 1260720556 On an HP-UX system, where date does *not* accept +%s bash-2.04$ uname -a HP-UX hpbox B.11.11 U 9000/785 2016698240 unlimited-user license bash-2.04$ ./unixtime date -u +%s 1260720771 date: bad format character - s On an OpenSolaris system, where date does *not* accept +%s bash-3.2$ ./unixtime date -u +%s 1260720823 %s On an IBM server running AIX 6.1, where date does accept +%s $ uname -a AIX client1 1 6 00C6B7C04C00 $ ./unixtime date -u +%s 1260721013 1260721013 For every system I am able to check this on, the following script gives exactly the same output as the GNU date command, but in a more portable manner. Could a few people check it on their systems. If it does work, I'd propose it is used in place of the GNUism introduced in http://trac.sagemath.org/sage_trac/ticket/6744 Currently the file .BUILDSTART created by #6744 is not actually used anywhere in Sage, but clearly the intension is to use it at some point, in which case it will be found not to work on some systems. Dave --- #!/bin/sh # Compute seconds since the Epoch. # Call 'date'. Note that # %Y = year including century # %j = day number (1-365) 1-366 that should be. # $2 = day number (1-365) Again, it goes up to 366 in leap years. The code takes leap years into account, and is said to work until 2100, in which case, we will all be dead. (or 2034 unless unix time is changed to a 64-bit number). Dave -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org
Re: [sage-devel] Please check if this computes seconds since Epoch
On 2009-Dec-13 16:27:41 +, Dr. David Kirkby david.kir...@onetel.net wrote: If you have a system with the GNU version of date, then date -u +%s will give the seconds since the Epoch. Unfortunately, it only works with GNU date, and so will not work on Solaris, HP-UX or no doubt many other Unix systems. FWIW, '%s' _does_ work with FreeBSD. For every system I am able to check this on, the following script gives exactly the same output as the GNU date command, but in a more portable manner. It works on FreeBSD/amd64 and FreeBSD/i386. It probably needs some more rigorous checking than it works today. Where did you find this particular algorithm - it's somewhat simpler than the one I use. # $5 = seconds (0-59) Whilst we're being pedantic, this should be (0..60) to allow for leap seconds. On 2009-Dec-13 17:05:25 +, Dr. David Kirkby david.kir...@onetel.net wrote: The code takes leap years into account, and is said to work until 2100, in which case, we will all be dead. (or 2034 unless unix time is changed to a 64-bit number). A few comments: - The 32-bit Unix epoch rolls over in 2038. - This also depends on the type expr(1) uses for integer math. - I wouldn't bet on everyone currently working on Sage being dead in 2100: If you're in your early 20's now, you'll be less that 115 then - which is not impossible today and will only become more common in future (assuming advances in medical science continue and aren't offset by a worsening environment). -- Peter Jeremy pgp7U3Zu8wcFY.pgp Description: PGP signature