Jump to content

[Linux BASh] - Help with syntax for comparing dates on HP-UX


Recommended Posts

This is regards a HP-UX box. I have the following;



# Exit script if program fails or an unset variable is used
set -eu


# Get expiry date of SSL certificate, in format 'Jan 31 11:59:00 2018 GMT'
enddate="$(openssl s_client -connect "$server:$port" 2>/dev/null | openssl x509 -noout -enddate | sed -e 's#notAfter=##')"

# Get today's date in format DD-MM-YYYY
todaysdate="$(date "+%d-%m-%Y")"
 echo "Today's date is $todaysdate"

# Convert $enddate to format DD-MM-YYYY
enddate_formatted=$(printf '%s\n' "$enddate" | awk '{printf "%02d-%02d-%04d\n",$2,(index("JanFebMarAprMayJunJulAugSepOctNovDec",$1)+2)/3,$4}')
 echo "Certificate expiry date is $enddate_formatted"

# Compare expiry date with today's date
if "$todaysdate" -ge "$("$enddate_formatted" - "$graceperiod_days")"
         then echo "$todaysdate is greater than $enddate_formatted. SSL certificate has expired!"
 elif "$todaysdate" -lt "$("$enddate_formatted" - "$graceperiod_days")"
         then echo "$todaysdate is before $enddate_formatted. Everything is OK!"
  echo "ERROR"; fi


As far as I can tell, this should work, however the output is;


Today's date is 29-08-2018
Certificate expiry date is 21-07-2018
./test[22]: 21-07-2018:  not found.
./test[22]: 29-08-2018:  not found.
./test[24]: 21-07-2018:  not found.
./test[24]: 29-08-2018:  not found.


What's going wrong?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...