Getting past dates in HP-UX with ksh

Posted by Alejandro Atienza Ramos on Stack Overflow See other posts from Stack Overflow or by Alejandro Atienza Ramos
Published on 2010-03-12T09:34:48Z Indexed on 2010/03/12 9:37 UTC
Read the original article Hit count: 615

Filed under:
|
|

Ok, so I need to translate a script from a nice linux & bash configuration to ksh in hp-ux. Each and every command expects a different syntax and i want to kill myself. But let's skip the rant.

This is part of my script

anterior=`date +"%Y%0m" -d '1 month ago'`

I basically need to get a past date in format 201002. Never mind the thing that, in the new environment, %0m means "no zeroes", while actually in the other one it means "yes, please put that zero on my string". It doesn't even accept the "1 month ago". I've read the man date for HP-UX and it seems you just can't do date arithmetic with it.

I've been looking around for a while but all i find are lengthy solutions. I can't quite understand that such a typical administrative task like adding dates needs so much fuss. Isn't there a way to convert my one-liner to, well, i don't know, another one? Come on, i've seen proposed solutions that used bc, had thirty plus lines and magic number all over the script. The simplest solutions seem to use perl... but i don't know how to modify them, as they're quite arcane.

Thanks!

© Stack Overflow or respective owner

Related posts about hp-ux

Related posts about ksh