datetime - How to convert a long date to short date from SSL certificates | Unix KSH -
i'm wondering if possible convert date show oct 31 00:00:00 2013 gmt 10-31-2013.
i'm getting date follow:
notbeforedate=$(openssl x509 -noout -in ${certificate} -dates | grep "notbefore") the date i'm getting oct 31 00:00:00 2013 gmt , wanted convert 10-31-2013.
there's command that? or have manually?
if so, best way create own function , send long date parameter , return short date.
the openssl command make notbeforedate variable have value (at least in bash version i'm using):
notbefore=oct 31 00:00:00 2013 gmt so, first need remove notbefore= part:
datestr=${notbeforedate/notbefore=/} then can use date command:
date --date="$datestr" --utc +"%m-%d-%y" the --date option tells command use datestr value, --utc tells date in utc (as specified gmt part) , +"%m-%d-%y" formats date desired format.
the output is:
10-31-2013
ps: options can vary according linux version.
can check available ones date --help or man date.
for example, long options --date , --utc might not available, equivalent short versions might (just example, i'm not sure if date command has such variations between different unix versions):
date -d "$datestr" -u +"%m-%d-%y" unfortunately don't have exact same environment you're using (ksh in unix), should work.
the -d options seems gnu specific, if it's not available, you'll have manually parse string. assuming datestr has value oct 31 00:00:00 2013 gmt, can run:
printf '%s\n' "$datestr" | awk '{ printf "%02d-%02d-%04d\n", (index("janfebmaraprmayjunjulaugsepoctnovdec",$1)+2)/3, $2, $4}' the output is:
10-31-2013
Comments
Post a Comment