Linux uses:
date -d "2 weeks ago" +%b
which is equivalent in Solaris?, I searched online, but nothing.
Linux uses:
date -d "2 weeks ago" +%b
which is equivalent in Solaris?, I searched online, but nothing.
Solaris' date
can't do that. AFAICT from the man page, it can't even display an arbitrary date, so you can't just get the date in seconds since the epoch, subtract 2 weeks (14 * 86400 = 1209600 seconds), and then give that to date +%b
.
If you can, install GNU date. Either under /usr/local/gnu/bin or similar if you have root (BTW, GNU Coreutils which contains GNU date is available pre-packaged for Solaris here), or in ~/bin if not.
If you can't install GNU date, your next best option would be to write a wrapper around strftime()
to do the calculation mentioned above, or write a 5-liner in perl or python both of which have excellent date handling libs.
gdate
in a way that makes it obvious for the user that he is not using the standard date
utility. While it is not that problem with date, there are many gnu utilities that miss important features you get with standard system features (e.g. ACL support) and some gnu utilities are even risky as e.g. gnu strip may destroy binaries because it misses complete ELF support.
– schily
Sep 26 '15 at 10:07
Just do gdate
instead of date
. This will give you GNU date as opposed to the traditional Solaris date command. This will work unless you are on a very old version of Solaris, i.e. Solaris 10 or before.
Note that if you are in a local zone then your sysadm may have decided for you that gdate
shouldn't be available, despite the fact that it is available by default in the global zone. In that case go tell him he's a ..... (use your own word here).
For more information: