title: Extracting an expiry date from a keytool certificate
body: <p>I am working on a fairly simple script to pull the expiry date from a keytool cert and compare this with todays date and then send a mail if that date is less than 30 days.  However where I am getting stuck is how to extract the expiry date using bash, I am running:</p>
  <pre><code>keytool -list -v -keystore /usr/java/jdk1.8.0_301-amd64/jre/lib/security/cacerts -storepass &lt;PWD&gt; | grep &quot;until:&quot;
  </code></pre>
  <p>Which will output all the certs stored with multiple lines as follows:</p>
  <pre><code>Valid from: Tue May 26 01:00:00 IST 2015 until: Sun Jan 17 00:00:00 GMT 2038
  </code></pre>
  <p>The plan is to take the expiry (until) date from the line and convert that to epoch seconds and days to help calculate in the script.</p>
  <p>Please can you suggest the best way for me to proceed.</p>