Solaris "days ago" alternative

Solaris "days ago" alternative

am 10.05.2005 11:57:36 von Wim

Hello group,

since yesterday I started to use Solaris. I could "translate" most of
my Linux-shell scripts, but still got one problem:

YESTERDAY=`date --date "1 days ago" +%d`

will not run. Is there a nice Solaris alternative?

Thanks in advance and have a nice day,

--wim

Re: Solaris "days ago" alternative

am 10.05.2005 13:00:43 von Keith Thompson

"wim" writes:
> since yesterday I started to use Solaris. I could "translate" most of
> my Linux-shell scripts, but still got one problem:
>
> YESTERDAY=`date --date "1 days ago" +%d`
>
> will not run. Is there a nice Solaris alternative?

You could write a small program (I'd use Perl) to do the job:

#!/usr/bin/perl -w
use strict;
printf "%02d\n", (localtime(time - 86400))[3];

Or you could install the GNU coreutils package, which includes the GNU
date command.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org
San Diego Supercomputer Center <*>
We must do something. This is something. Therefore, we must do this.

Re: Solaris "days ago" alternative

am 10.05.2005 13:16:21 von Wim

ok, thank you very much :-)

Greetings,

--wim

Re: Solaris "days ago" alternative

am 10.05.2005 14:33:55 von Ed Morton

wim wrote:
> Hello group,
>
> since yesterday I started to use Solaris. I could "translate" most of
> my Linux-shell scripts, but still got one problem:
>
> YESTERDAY=`date --date "1 days ago" +%d`
>
> will not run. Is there a nice Solaris alternative?

See question 6 in the FAQ (http://home.comcast.net/~j.p.h/cus-faq.html#G).

Ed.

Re: Solaris "days ago" alternative

am 10.05.2005 17:47:34 von Wim

Thank you, I should have checked there first of course (shame). I think
I will try the GNU-coreutils alternative anyway, I really prefer the
syntax that I am familiar with :-)

Re: Solaris "days ago" alternative

am 11.05.2005 12:54:51 von vansteijn

wim wrote:

>Hello group,
>
>since yesterday I started to use Solaris. I could "translate" most of
>my Linux-shell scripts, but still got one problem:
>
> YESTERDAY=`date --date "1 days ago" +%d`
>
>will not run. Is there a nice Solaris alternative?
>
>Thanks in advance and have a nice day,
>
> --wim
>
>
>
A two step solution

YESTERDAY=`date "+%d"`;YESTERDAY="`expr $YESTERDAY - 1`"

Succes

Re: Solaris "days ago" alternative

am 11.05.2005 15:11:41 von Loki Harfagr

Le Wed, 11 May 2005 12:54:51 +0200, A.van.Steijn a écrit :

> A two step solution
>
> YESTERDAY=`date "+%d"`;YESTERDAY="`expr $YESTERDAY - 1`"

Until next 1st of the month :-)

Re: Solaris "days ago" alternative

am 11.05.2005 20:48:37 von Keith Thompson

Loki Harfagr writes:
> Le Wed, 11 May 2005 12:54:51 +0200, A.van.Steijn a écrit :
>
>> A two step solution
>>
>> YESTERDAY=`date "+%d"`;YESTERDAY="`expr $YESTERDAY - 1`"
>
> Until next 1st of the month :-)

It also loses the leading 0. "date +%d" prints "05" on the fifth of
the month; "expr 05 - 1" prints "4", not "04".

--
Keith Thompson (The_Other_Keith) kst-u@mib.org
San Diego Supercomputer Center <*>
We must do something. This is something. Therefore, we must do this.