<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://wiki.twig.es/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.twig.es/index.php?action=history&amp;feed=atom&amp;title=The_Bourne_shell_script_to_query_for_certs</id>
		<title>The Bourne shell script to query for certs - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.twig.es/index.php?action=history&amp;feed=atom&amp;title=The_Bourne_shell_script_to_query_for_certs"/>
		<link rel="alternate" type="text/html" href="https://wiki.twig.es/index.php?title=The_Bourne_shell_script_to_query_for_certs&amp;action=history"/>
		<updated>2026-05-06T15:48:05Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.0</generator>

	<entry>
		<id>https://wiki.twig.es/index.php?title=The_Bourne_shell_script_to_query_for_certs&amp;diff=4270&amp;oldid=prev</id>
		<title>George2 at 11:13, 22 January 2019</title>
		<link rel="alternate" type="text/html" href="https://wiki.twig.es/index.php?title=The_Bourne_shell_script_to_query_for_certs&amp;diff=4270&amp;oldid=prev"/>
				<updated>2019-01-22T11:13:00Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 11:13, 22 January 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[ SSL cert project implementation plan ]]&amp;lt;br&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The script was sourced here :&amp;#160; https://prefetch.net/articles/checkcertificate.html&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The script was sourced here :&amp;#160; https://prefetch.net/articles/checkcertificate.html&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ssl-cert-check -i -f ssldomains&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ssl-cert-check -i -f ssldomains&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>George2</name></author>	</entry>

	<entry>
		<id>https://wiki.twig.es/index.php?title=The_Bourne_shell_script_to_query_for_certs&amp;diff=4269&amp;oldid=prev</id>
		<title>George2 at 10:52, 22 January 2019</title>
		<link rel="alternate" type="text/html" href="https://wiki.twig.es/index.php?title=The_Bourne_shell_script_to_query_for_certs&amp;diff=4269&amp;oldid=prev"/>
				<updated>2019-01-22T10:52:23Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 10:52, 22 January 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The script was sourced here :&amp;#160; https://prefetch.net/articles/checkcertificate.html&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The script was sourced here :&amp;#160; https://prefetch.net/articles/checkcertificate.html&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;br&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;ssl-cert-check -i -f ssldomains&amp;lt;br&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;prefetch.com 443&amp;lt;br&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#!/usr/bin/env bash&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#!/usr/bin/env bash&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>George2</name></author>	</entry>

	<entry>
		<id>https://wiki.twig.es/index.php?title=The_Bourne_shell_script_to_query_for_certs&amp;diff=4268&amp;oldid=prev</id>
		<title>George2: Created page with &quot;The script was sourced here :  https://prefetch.net/articles/checkcertificate.html &lt;source lang=&quot;bash&quot;&gt; #!/usr/bin/env bash # # Program: SSL Certificate Check &lt;ssl-cert-check&gt;...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.twig.es/index.php?title=The_Bourne_shell_script_to_query_for_certs&amp;diff=4268&amp;oldid=prev"/>
				<updated>2019-01-22T10:51:17Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;The script was sourced here :  https://prefetch.net/articles/checkcertificate.html &amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt; #!/usr/bin/env bash # # Program: SSL Certificate Check &amp;lt;ssl-cert-check&amp;gt;...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The script was sourced here :  https://prefetch.net/articles/checkcertificate.html&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env bash&lt;br /&gt;
#&lt;br /&gt;
# Program: SSL Certificate Check &amp;lt;ssl-cert-check&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# Source code home: https://github.com/Matty9191/ssl-cert-check&lt;br /&gt;
#&lt;br /&gt;
# Documentation: http://prefetch.net/articles/checkcertificate.html&lt;br /&gt;
#&lt;br /&gt;
# Author: Matty &amp;lt; matty91 at gmail dot com &amp;gt;&lt;br /&gt;
#&lt;br /&gt;
# Current Version: 3.30&lt;br /&gt;
#&lt;br /&gt;
# Revision History:&lt;br /&gt;
#&lt;br /&gt;
# Version 3.31&lt;br /&gt;
#  - Fixed the test for the -servername flag -- Kitson Consulting.&lt;br /&gt;
#&lt;br /&gt;
# Version 3.30&lt;br /&gt;
#  - Use highest returncode for Nagios output -- Marcel Pennewiss&lt;br /&gt;
#  - Set RETCODE to 3 (unknown) if a certificate file does not exist -- Marcel Pennewiss&lt;br /&gt;
#  - Add a &amp;quot;-d&amp;quot; option to specify a directory or file mask pattern -- Marcel Pennewiss&lt;br /&gt;
#  - Add a &amp;quot;-N&amp;quot; option to create summarized Nagios output -- Marcel Pennewiss&lt;br /&gt;
#  - Cleaned up many formatting -- Marcel Pennewiss&lt;br /&gt;
#&lt;br /&gt;
# Versione 3.29a&lt;br /&gt;
#  - Added option to specify email sender address&lt;br /&gt;
#&lt;br /&gt;
# Version 3.29&lt;br /&gt;
#  - Add the openssl -servername flag if it shows up in help.&lt;br /&gt;
#&lt;br /&gt;
# Version 3.28&lt;br /&gt;
#  - Added a DEBUG option to assist with debugging folks who use the script&lt;br /&gt;
#&lt;br /&gt;
# Version 3.27&lt;br /&gt;
#  - Allow white spaces to exist in the certificate file list&lt;br /&gt;
#  - Add an additional check to pick up bad / non-existent certificates&lt;br /&gt;
#  - Add a check to look for the existence of a mail program. Error out if it's not present.&lt;br /&gt;
#  - Enable the TLS -servername extension by default - Juergen Knaack &amp;amp; Johan Denoyer&lt;br /&gt;
#&lt;br /&gt;
# Version 3.26&lt;br /&gt;
#  - Allow the certificate type (PEM, DER, NET) to be passed on the command line&lt;br /&gt;
#&lt;br /&gt;
# Version 3.25&lt;br /&gt;
#   - Check for &amp;quot;no route to host&amp;quot; errors -- Dan Doyle&lt;br /&gt;
#   - Set RETCODE to 3 (unknown) if a connection error occurs -- Dan Doyle&lt;br /&gt;
#   - Documentation fixes&lt;br /&gt;
#&lt;br /&gt;
# Version 3.24&lt;br /&gt;
#   - Utilize the -clcerts option to limit the results to client certificates - Eitan Katznelson&lt;br /&gt;
#&lt;br /&gt;
# Version 3.23&lt;br /&gt;
#   - Fixed typo in date2julian routine -- Ken Cook&lt;br /&gt;
#&lt;br /&gt;
# Version 3.22&lt;br /&gt;
#   - Change the validation option to &amp;quot;-V&amp;quot;&lt;br /&gt;
#   - Add a &amp;quot;-v&amp;quot; option to specify a specific protocol version (ssl2, ssl3 or tls)&lt;br /&gt;
#&lt;br /&gt;
# Version 3.21&lt;br /&gt;
#   - Adjust e-mail checking to avoid exiting if notifications aren't enabled -- Nick Anderson&lt;br /&gt;
#   - Added the number of days until expiration to the Nagios output -- Nick Anderson&lt;br /&gt;
#&lt;br /&gt;
# Version 3.20&lt;br /&gt;
#   - Fixed a bug in certificate length checking -- Tim Nowaczyk&lt;br /&gt;
#&lt;br /&gt;
# Version 3.19&lt;br /&gt;
#   - Added check to verify the certificate retrieved is valid&lt;br /&gt;
#&lt;br /&gt;
# Version 3.18&lt;br /&gt;
#   - Add support for connecting to FTP servers -- Paul A Sand&lt;br /&gt;
#&lt;br /&gt;
# Version 3.17&lt;br /&gt;
#   - Add support for connecting to imap servers -- Joerg Pareigis&lt;br /&gt;
#&lt;br /&gt;
# Version 3.16&lt;br /&gt;
#   - Add support for connecting to the mail sbmission port -- Luis E. Munoz&lt;br /&gt;
#&lt;br /&gt;
# Version 3.15&lt;br /&gt;
#   - Adjusted the file checking logic to use the correct certificate -- Maciej Szudejko&lt;br /&gt;
#   - Add sbin to the default search paths for OpenBSD compatibility -- Alex Popov&lt;br /&gt;
#   - Use cut instead of substring processing to ensure compatibility -- Alex Popov&lt;br /&gt;
#&lt;br /&gt;
# Version 3.14&lt;br /&gt;
#   - Fixed the Common Name parser to handle DN's where the CN is not the last item&lt;br /&gt;
#     eg. EmailAddr -- Jason Brothers&lt;br /&gt;
#   - Added the ability to grab the serial number -- Jason Brothers&lt;br /&gt;
#   - Added the &amp;quot;-b&amp;quot; option to print results without a header -- Jason Brothers&lt;br /&gt;
#   - Added the &amp;quot;-v&amp;quot; option for certificate validation -- Jason Brothers&lt;br /&gt;
#&lt;br /&gt;
# Version 3.13&lt;br /&gt;
#   - Updated the subject line to include the hostname as well as&lt;br /&gt;
#     the common name embedded in the X509 certificate (if it's&lt;br /&gt;
#     available) -- idea proposed by Mike Burns&lt;br /&gt;
#&lt;br /&gt;
#  Version 3.12&lt;br /&gt;
#   - Updated the license to allow redistribution and modification&lt;br /&gt;
#&lt;br /&gt;
#  Version 3.11&lt;br /&gt;
#   - Added ability to comment out lines in files passed&lt;br /&gt;
#     to the &amp;quot;-f&amp;quot; option -- Brett Stauner&lt;br /&gt;
#   - Fixed comment next to file processing logic&lt;br /&gt;
#&lt;br /&gt;
#  Version 3.10&lt;br /&gt;
#   - Fixed POP3 port -- Simon Matter&lt;br /&gt;
#&lt;br /&gt;
#  Version 3.9&lt;br /&gt;
#    - Switched binary location logic to use which utility&lt;br /&gt;
#&lt;br /&gt;
#  Version 3.8&lt;br /&gt;
#    - Fixed display on 80 column displays&lt;br /&gt;
#    - Cleaned up the formatting&lt;br /&gt;
#&lt;br /&gt;
#  Version 3.7&lt;br /&gt;
#    - Fixed bug in NAGIOS tests -- Ben Allen&lt;br /&gt;
#&lt;br /&gt;
#  Version 3.6&lt;br /&gt;
#    - Added support for certificates stored in PKCS#12 databases -- Ken Gallo&lt;br /&gt;
#    - Cleaned up comments&lt;br /&gt;
#    - Adjusted variables to be more consistent&lt;br /&gt;
#&lt;br /&gt;
#  Version 3.5&lt;br /&gt;
#    - Added support for NAGIOS -- Quanah Gibson-Mount&lt;br /&gt;
#    - Added additional checks for mail -- Quanah Gibson-Mount&lt;br /&gt;
#    - Convert tabs to spaces -- Quanah Gibson-Mount&lt;br /&gt;
#    - Cleaned up usage() routine&lt;br /&gt;
#    - Added additional checks for openssl&lt;br /&gt;
#&lt;br /&gt;
#  Version 3.4&lt;br /&gt;
#   - Added a missing &amp;quot;{&amp;quot; to line 364 -- Ken Gallo&lt;br /&gt;
#   - Move mktemp to the start of the main body to avoid errors&lt;br /&gt;
#   - Adjusted default binary paths to make sure the script just works&lt;br /&gt;
#     w/ Solaris, BSD and Linux hosts&lt;br /&gt;
#&lt;br /&gt;
#  Version 3.3&lt;br /&gt;
#   - Added common name from X.509 certificate file to E-mail body / header -- Doug Curtis&lt;br /&gt;
#   - Fixed several documentation errors&lt;br /&gt;
#   - Use mktemp to create temporary files&lt;br /&gt;
#   - Convert printf, sed and awk to variables&lt;br /&gt;
#   - Check for printf, sed, awk and mktemp binaries&lt;br /&gt;
#   - Add additional logic to make sure mktemp returned a valid temporary file&lt;br /&gt;
#&lt;br /&gt;
#  Version 3.2&lt;br /&gt;
#   - Added option to list certificates in the file passed to &amp;quot;-f&amp;quot;.&lt;br /&gt;
#&lt;br /&gt;
#  Version 3.1&lt;br /&gt;
#   - Added handling for starttls for smtp -- Marco Amrein&lt;br /&gt;
#   - Added handling for starttls for pop3 (without s) -- Marco Amrein&lt;br /&gt;
#   - Removed extra spacing at end of script&lt;br /&gt;
#&lt;br /&gt;
#  Version 3.0&lt;br /&gt;
#   - Added &amp;quot;-i&amp;quot; option to print certificate issuer&lt;br /&gt;
#   - Removed $0 from Subject line of outbound e-mails&lt;br /&gt;
#   - Fixed some typographical errors&lt;br /&gt;
#   - Removed redundant &amp;quot;-b&amp;quot; option&lt;br /&gt;
#&lt;br /&gt;
#  Version 2.0&lt;br /&gt;
#    - Fixed an issue with e-mails formatting incorrectly&lt;br /&gt;
#    - Added additional space to host column -- Darren-Perot Spruell&lt;br /&gt;
#    - Replaced GNU date dependency with CHRIS F. A. JOHNSON's&lt;br /&gt;
#      date2julian shell function. This routine can be found on&lt;br /&gt;
#      page 170 of Chris's book &amp;quot;Shell Scripting Recipes: A&lt;br /&gt;
#      Problem-Solution Approach,&amp;quot; ISBN #1590594711. Julian function&lt;br /&gt;
#      was created based on a post to comp.unix.shell by Tapani Tarvainen.&lt;br /&gt;
#    - Cleaned up function descriptions&lt;br /&gt;
#    - Removed several lines of redundant code&lt;br /&gt;
#    - Adjusted the help message&lt;br /&gt;
#&lt;br /&gt;
#   Version 1.1&lt;br /&gt;
#    - Added &amp;quot;-c&amp;quot; flag to report expiration status of a PEM encoded&lt;br /&gt;
#      certificate -- Hampus Lundqvist&lt;br /&gt;
#    - Updated the prints messages to display the reason a connection&lt;br /&gt;
#      failed (connection refused, connection timeout, bad cert, etc)&lt;br /&gt;
#    - Updated the GNU date checking routines&lt;br /&gt;
#    - Added checks for each binary required&lt;br /&gt;
#    - Added checks for connection timeouts&lt;br /&gt;
#    - Added checks for GNU date&lt;br /&gt;
#    - Added a &amp;quot;-h&amp;quot; option&lt;br /&gt;
#    - Cleaned up the documentation&lt;br /&gt;
#&lt;br /&gt;
#  Version 1.0&lt;br /&gt;
#      Initial Release&lt;br /&gt;
#&lt;br /&gt;
# Last Updated: 12-12-2016&lt;br /&gt;
#&lt;br /&gt;
# Purpose:&lt;br /&gt;
#  ssl-cert-check checks to see if a digital certificate in X.509 format&lt;br /&gt;
#  has expired. ssl-cert-check can be run in interactive and batch mode,&lt;br /&gt;
#  and provides facilities to alarm if a certificate is about to expire.&lt;br /&gt;
#&lt;br /&gt;
# License:&lt;br /&gt;
#  This program is free software; you can redistribute it and/or modify&lt;br /&gt;
#  it under the terms of the GNU General Public License as published by&lt;br /&gt;
#  the Free Software Foundation; either version 2 of the License, or&lt;br /&gt;
#  (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
#  This program is distributed in the hope that it will be useful,&lt;br /&gt;
#  but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the&lt;br /&gt;
#  GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
# Requirements:&lt;br /&gt;
#   Requires openssl&lt;br /&gt;
#&lt;br /&gt;
# Installation:&lt;br /&gt;
#   Copy the shell script to a suitable location&lt;br /&gt;
#&lt;br /&gt;
# Tested platforms:&lt;br /&gt;
#  -- Solaris 9 using /bin/bash&lt;br /&gt;
#  -- Solaris 10 using /bin/bash&lt;br /&gt;
#  -- OS X 10.4.2 using /bin/bash&lt;br /&gt;
#  -- OpenBSD using /bin/sh&lt;br /&gt;
#  -- FreeBSD using /bin/sh&lt;br /&gt;
#  -- Centos Linux 3, 4, 5 &amp;amp; 6 using /bin/bash&lt;br /&gt;
#  -- Redhat Enterprise Linux 3, 4, 5 &amp;amp; 6 using /bin/bash&lt;br /&gt;
#  -- Gentoo using /bin/bash&lt;br /&gt;
#&lt;br /&gt;
# Usage:&lt;br /&gt;
#  Refer to the usage() sub-routine, or invoke ssl-cert-check&lt;br /&gt;
#  with the &amp;quot;-h&amp;quot; option.&lt;br /&gt;
#&lt;br /&gt;
# Examples:&lt;br /&gt;
#   Please refer to the following site for documentation and examples:&lt;br /&gt;
#   http://prefetch.net/articles/checkcertificate.html&lt;br /&gt;
&lt;br /&gt;
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/ssl/bin:/usr/sfw/bin&lt;br /&gt;
export PATH&lt;br /&gt;
&lt;br /&gt;
# Who to page when an expired certificate is detected (cmdline: -e)&lt;br /&gt;
ADMIN=&amp;quot;root&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Email sender address for alarm notifications&lt;br /&gt;
SENDER=&amp;quot;postmaster@localhost.localdomain&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Number of days in the warning threshhold (cmdline: -x)&lt;br /&gt;
WARNDAYS=30&lt;br /&gt;
&lt;br /&gt;
# If QUIET is set to TRUE, don't print anything on the console (cmdline: -q)&lt;br /&gt;
QUIET=&amp;quot;FALSE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Don't send E-mail by default (cmdline: -a)&lt;br /&gt;
ALARM=&amp;quot;FALSE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Don't run as a Nagios plugin by default (cmdline: -n)&lt;br /&gt;
NAGIOS=&amp;quot;FALSE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Don't summarize Nagios output by default (cmdline: -N)&lt;br /&gt;
NAGIOSSUMMARY=&amp;quot;FALSE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# NULL out the PKCSDBPASSWD variable for later use (cmdline: -k)&lt;br /&gt;
PKCSDBPASSWD=&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Type of certificate (PEM, DER, NET) (cmdline: -t)&lt;br /&gt;
CERTTYPE=&amp;quot;pem&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Protocol version to use (cmdline: -v)&lt;br /&gt;
VERSION=&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Enable debugging&lt;br /&gt;
DEBUG=0&lt;br /&gt;
&lt;br /&gt;
# Location of system binaries&lt;br /&gt;
AWK=$(which awk)&lt;br /&gt;
DATE=$(which date)&lt;br /&gt;
GREP=$(which grep)&lt;br /&gt;
OPENSSL=$(which openssl)&lt;br /&gt;
PRINTF=$(which printf)&lt;br /&gt;
SED=$(which sed)&lt;br /&gt;
MKTEMP=$(which mktemp)&lt;br /&gt;
FIND=$(which find)&lt;br /&gt;
&lt;br /&gt;
# Try to find a mail client&lt;br /&gt;
if [ -f /usr/bin/mailx ]&lt;br /&gt;
then&lt;br /&gt;
    MAIL=&amp;quot;/usr/bin/mailx&amp;quot;&lt;br /&gt;
    MAILMODE=&amp;quot;mailx&amp;quot;&lt;br /&gt;
elif [ -f /bin/mail ]&lt;br /&gt;
then&lt;br /&gt;
    MAIL=&amp;quot;/bin/mail&amp;quot;&lt;br /&gt;
    MAILMODE=&amp;quot;mail&amp;quot;&lt;br /&gt;
elif [ -f /usr/bin/mail ]&lt;br /&gt;
then&lt;br /&gt;
    MAIL=&amp;quot;/usr/bin/mail&amp;quot;&lt;br /&gt;
    MAILMODE=&amp;quot;mail&amp;quot;&lt;br /&gt;
elif [ -f /sbin/mail ]&lt;br /&gt;
then&lt;br /&gt;
    MAIL=&amp;quot;/sbin/mail&amp;quot;&lt;br /&gt;
    MAILMODE=&amp;quot;mail&amp;quot;&lt;br /&gt;
elif [ -f /usr/sbin/mail ]&lt;br /&gt;
then&lt;br /&gt;
    MAIL=&amp;quot;/usr/sbin/mail&amp;quot;&lt;br /&gt;
    MAILMODE=&amp;quot;mail&amp;quot;&lt;br /&gt;
elif [ -f /usr/sbin/sendmail ]&lt;br /&gt;
then&lt;br /&gt;
    MAIL=&amp;quot;/usr/sbin/sendmail&amp;quot;&lt;br /&gt;
    MAILMODE=&amp;quot;sendmail&amp;quot;    &lt;br /&gt;
else&lt;br /&gt;
    MAIL=&amp;quot;cantfindit&amp;quot;&lt;br /&gt;
    MAILMODE=&amp;quot;cantfindit&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Return code used by nagios. Initialize to 0.&lt;br /&gt;
RETCODE=0&lt;br /&gt;
&lt;br /&gt;
# Certificate counters and minimum difference. Initialize to 0.&lt;br /&gt;
SUMMARY_VALID=0&lt;br /&gt;
SUMMARY_WILL_EXPIRE=0&lt;br /&gt;
SUMMARY_EXPIRED=0&lt;br /&gt;
SUMMARY_MIN_DIFF=0&lt;br /&gt;
SUMMARY_MIN_DATE=&lt;br /&gt;
SUMMARY_MIN_HOST=&lt;br /&gt;
SUMMARY_MIN_PORT=&lt;br /&gt;
&lt;br /&gt;
# Set the default umask to be somewhat restrictive&lt;br /&gt;
umask 077&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#####################################################&lt;br /&gt;
### Send email&lt;br /&gt;
### Accepts three parameters:&lt;br /&gt;
###  $1 -&amp;gt; sender email address&lt;br /&gt;
###  $2 -&amp;gt; email to send mail&lt;br /&gt;
###  $3 -&amp;gt; Subject&lt;br /&gt;
###  $4 -&amp;gt; Message&lt;br /&gt;
#####################################################&lt;br /&gt;
send_mail() {&lt;br /&gt;
&lt;br /&gt;
    FROM=${1}&lt;br /&gt;
    TO=${2}&lt;br /&gt;
    SUBJECT=${3}&lt;br /&gt;
    MSG=${4}&lt;br /&gt;
&lt;br /&gt;
    case &amp;quot;${MAILMODE}&amp;quot; in&lt;br /&gt;
        &amp;quot;mail&amp;quot; | &amp;quot;mailx&amp;quot;)&lt;br /&gt;
            echo &amp;quot;$MSG&amp;quot; | ${MAIL} -r $FROM -s &amp;quot;$SUBJECT&amp;quot; $TO&lt;br /&gt;
            ;;&lt;br /&gt;
        &amp;quot;sendmail&amp;quot;)&lt;br /&gt;
            (echo &amp;quot;Subject:$SUBJECT&amp;quot; &amp;amp;&amp;amp; echo &amp;quot;TO:$TO&amp;quot; &amp;amp;&amp;amp; echo &amp;quot;FROM:$FROM&amp;quot; &amp;amp;&amp;amp; echo &amp;quot;$MSG&amp;quot;) | ${MAIL} $TO&lt;br /&gt;
            ;;&lt;br /&gt;
        &amp;quot;*&amp;quot;)&lt;br /&gt;
            echo &amp;quot;ERROR: You enabled automated alerts, but the mail binary could not be found.&amp;quot;&lt;br /&gt;
            echo &amp;quot;FIX: Please modify the ${MAIL} and ${$MAILMODE} variable in the program header.&amp;quot;&lt;br /&gt;
            exit 1&lt;br /&gt;
            ;;&lt;br /&gt;
    esac&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#############################################################################&lt;br /&gt;
# Purpose: Convert a date from MONTH-DAY-YEAR to Julian format&lt;br /&gt;
# Acknowledgements: Code was adapted from examples in the book&lt;br /&gt;
#                   &amp;quot;Shell Scripting Recipes: A Problem-Solution Approach&amp;quot;&lt;br /&gt;
#                   ( ISBN 1590594711 )&lt;br /&gt;
# Arguments:&lt;br /&gt;
#   $1 -&amp;gt; Month (e.g., 06)&lt;br /&gt;
#   $2 -&amp;gt; Day   (e.g., 08)&lt;br /&gt;
#   $3 -&amp;gt; Year  (e.g., 2006)&lt;br /&gt;
#############################################################################&lt;br /&gt;
date2julian() {&lt;br /&gt;
&lt;br /&gt;
    if [ &amp;quot;${1}&amp;quot; != &amp;quot;&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${2}&amp;quot; != &amp;quot;&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${3}&amp;quot; != &amp;quot;&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        ## Since leap years add aday at the end of February,&lt;br /&gt;
        ## calculations are done from 1 March 0000 (a fictional year)&lt;br /&gt;
        d2j_tmpmonth=$((12 * ${3} + ${1} - 3))&lt;br /&gt;
&lt;br /&gt;
        ## If it is not yet March, the year is changed to the previous year&lt;br /&gt;
        d2j_tmpyear=$(( ${d2j_tmpmonth} / 12))&lt;br /&gt;
&lt;br /&gt;
        ## The number of days from 1 March 0000 is calculated&lt;br /&gt;
        ## and the number of days from 1 Jan. 4713BC is added&lt;br /&gt;
        echo $(( (734 * ${d2j_tmpmonth} + 15) / 24&lt;br /&gt;
                 - 2 * ${d2j_tmpyear} + ${d2j_tmpyear}/4&lt;br /&gt;
                 - ${d2j_tmpyear}/100 + ${d2j_tmpyear}/400 + $2 + 1721119 ))&lt;br /&gt;
    else&lt;br /&gt;
        echo 0&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#############################################################################&lt;br /&gt;
# Purpose: Convert a string month into an integer representation&lt;br /&gt;
# Arguments:&lt;br /&gt;
#   $1 -&amp;gt; Month name (e.g., Sep)&lt;br /&gt;
#############################################################################&lt;br /&gt;
getmonth()&lt;br /&gt;
{&lt;br /&gt;
    case ${1} in&lt;br /&gt;
        Jan) echo 1 ;;&lt;br /&gt;
        Feb) echo 2 ;;&lt;br /&gt;
        Mar) echo 3 ;;&lt;br /&gt;
        Apr) echo 4 ;;&lt;br /&gt;
        May) echo 5 ;;&lt;br /&gt;
        Jun) echo 6 ;;&lt;br /&gt;
        Jul) echo 7 ;;&lt;br /&gt;
        Aug) echo 8 ;;&lt;br /&gt;
        Sep) echo 9 ;;&lt;br /&gt;
        Oct) echo 10 ;;&lt;br /&gt;
        Nov) echo 11 ;;&lt;br /&gt;
        Dec) echo 12 ;;&lt;br /&gt;
          *) echo 0 ;;&lt;br /&gt;
    esac&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#############################################################################&lt;br /&gt;
# Purpose: Calculate the number of seconds between two dates&lt;br /&gt;
# Arguments:&lt;br /&gt;
#   $1 -&amp;gt; Date #1&lt;br /&gt;
#   $2 -&amp;gt; Date #2&lt;br /&gt;
#############################################################################&lt;br /&gt;
date_diff()&lt;br /&gt;
{&lt;br /&gt;
    if [ &amp;quot;${1}&amp;quot; != &amp;quot;&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${2}&amp;quot; != &amp;quot;&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        echo $((${2} - ${1}))&lt;br /&gt;
    else&lt;br /&gt;
        echo 0&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#####################################################################&lt;br /&gt;
# Purpose: Print a line with the expiraton interval&lt;br /&gt;
# Arguments:&lt;br /&gt;
#   $1 -&amp;gt; Hostname&lt;br /&gt;
#   $2 -&amp;gt; TCP Port&lt;br /&gt;
#   $3 -&amp;gt; Status of certification (e.g., expired or valid)&lt;br /&gt;
#   $4 -&amp;gt; Date when certificate will expire&lt;br /&gt;
#   $5 -&amp;gt; Days left until the certificate will expire&lt;br /&gt;
#   $6 -&amp;gt; Issuer of the certificate&lt;br /&gt;
#####################################################################&lt;br /&gt;
prints()&lt;br /&gt;
{&lt;br /&gt;
    if [ &amp;quot;${NAGIOSSUMMARY}&amp;quot; == &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        return&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    if [ &amp;quot;${QUIET}&amp;quot; != &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${ISSUER}&amp;quot; = &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${VALIDATION}&amp;quot; != &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        MIN_DATE=$(echo $4 | ${AWK} '{ print $1, $2, $4 }')&lt;br /&gt;
        if [ &amp;quot;${NAGIOS}&amp;quot; == &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
            ${PRINTF} &amp;quot;%-35s %-17s %-8s %-11s %-4s %-30s\n&amp;quot; &amp;quot;$1:$2&amp;quot; &amp;quot;$6&amp;quot; &amp;quot;$3&amp;quot; &amp;quot;$MIN_DATE&amp;quot; \|days=&amp;quot;$5&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
            ${PRINTF} &amp;quot;%-35s %-17s %-8s %-11s %-4s %-30s\n&amp;quot; &amp;quot;$1:$2&amp;quot; &amp;quot;$6&amp;quot; &amp;quot;$3&amp;quot; &amp;quot;$MIN_DATE&amp;quot; &amp;quot;$5&amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
    elif [ &amp;quot;${QUIET}&amp;quot; != &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${ISSUER}&amp;quot; = &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${VALIDATION}&amp;quot; == &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        ${PRINTF} &amp;quot;%-35s %-35s %-32s %-17s\n&amp;quot; &amp;quot;$1:$2&amp;quot; &amp;quot;$7&amp;quot; &amp;quot;$8&amp;quot; &amp;quot;$6&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    elif [ &amp;quot;${QUIET}&amp;quot; != &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${VALIDATION}&amp;quot; != &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        MIN_DATE=$(echo $4 | ${AWK} '{ print $1, $2, $4 }')&lt;br /&gt;
        if [ &amp;quot;${NAGIOS}&amp;quot; == &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
            ${PRINTF} &amp;quot;%-47s %-12s %-12s %-4s %-30s\n&amp;quot; &amp;quot;$1:$2&amp;quot; &amp;quot;$3&amp;quot; &amp;quot;$MIN_DATE&amp;quot; \|days=&amp;quot;$5&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
            ${PRINTF} &amp;quot;%-47s %-12s %-12s %-4s %-30s\n&amp;quot; &amp;quot;$1:$2&amp;quot; &amp;quot;$3&amp;quot; &amp;quot;$MIN_DATE&amp;quot; &amp;quot;$5&amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
    elif [ &amp;quot;${QUIET}&amp;quot; != &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${VALIDATION}&amp;quot; == &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        ${PRINTF} &amp;quot;%-35s %-35s %-32s\n&amp;quot; &amp;quot;$1:$2&amp;quot; &amp;quot;$7&amp;quot; &amp;quot;$8&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
####################################################&lt;br /&gt;
# Purpose: Print a heading with the relevant columns&lt;br /&gt;
# Arguments:&lt;br /&gt;
#   None&lt;br /&gt;
####################################################&lt;br /&gt;
print_heading()&lt;br /&gt;
{&lt;br /&gt;
    if [ &amp;quot;${NOHEADER}&amp;quot; != &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        if [ &amp;quot;${QUIET}&amp;quot; != &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${ISSUER}&amp;quot; = &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${NAGIOS}&amp;quot; != &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${VALIDATION}&amp;quot; != &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
            ${PRINTF} &amp;quot;\n%-35s %-17s %-8s %-11s %-4s\n&amp;quot; &amp;quot;Host&amp;quot; &amp;quot;Issuer&amp;quot; &amp;quot;Status&amp;quot; &amp;quot;Expires&amp;quot; &amp;quot;Days&amp;quot;&lt;br /&gt;
            echo &amp;quot;----------------------------------- ----------------- -------- ----------- ----&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        elif [ &amp;quot;${QUIET}&amp;quot; != &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${ISSUER}&amp;quot; = &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${NAGIOS}&amp;quot; != &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${VALIDATION}&amp;quot; == &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
            ${PRINTF} &amp;quot;\n%-35s %-35s %-32s %-17s\n&amp;quot; &amp;quot;Host&amp;quot; &amp;quot;Common Name&amp;quot; &amp;quot;Serial #&amp;quot; &amp;quot;Issuer&amp;quot;&lt;br /&gt;
            echo &amp;quot;----------------------------------- ----------------------------------- -------------------------------- -----------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        elif [ &amp;quot;${QUIET}&amp;quot; != &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${NAGIOS}&amp;quot; != &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${VALIDATION}&amp;quot; != &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
            ${PRINTF} &amp;quot;\n%-47s %-12s %-12s %-4s\n&amp;quot; &amp;quot;Host&amp;quot; &amp;quot;Status&amp;quot; &amp;quot;Expires&amp;quot; &amp;quot;Days&amp;quot;&lt;br /&gt;
            echo &amp;quot;----------------------------------------------- ------------ ------------ ----&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        elif [ &amp;quot;${QUIET}&amp;quot; != &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${NAGIOS}&amp;quot; != &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${VALIDATION}&amp;quot; == &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
            ${PRINTF} &amp;quot;\n%-35s %-35s %-32s\n&amp;quot; &amp;quot;Host&amp;quot; &amp;quot;Common Name&amp;quot; &amp;quot;Serial #&amp;quot;&lt;br /&gt;
            echo &amp;quot;----------------------------------- ----------------------------------- --------------------------------&amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
####################################################&lt;br /&gt;
# Purpose: Print a summary for nagios&lt;br /&gt;
# Arguments:&lt;br /&gt;
#   None&lt;br /&gt;
####################################################&lt;br /&gt;
print_summary()&lt;br /&gt;
{&lt;br /&gt;
    if [ &amp;quot;${NAGIOSSUMMARY}&amp;quot; != &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        return&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    if [ ${SUMMARY_WILL_EXPIRE} -eq 0 ] &amp;amp;&amp;amp; [ ${SUMMARY_EXPIRED} -eq 0 ]&lt;br /&gt;
    then&lt;br /&gt;
        ${PRINTF} &amp;quot;%s valid certificate(s)|days=%s\n&amp;quot; &amp;quot;${SUMMARY_VALID}&amp;quot; &amp;quot;${SUMMARY_MIN_DIFF}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    elif [ ${SUMMARY_EXPIRED} -ne 0 ]&lt;br /&gt;
    then&lt;br /&gt;
        ${PRINTF} &amp;quot;%s certificate(s) expired (%s:%s on %s)|days=%s\n&amp;quot; &amp;quot;${SUMMARY_EXPIRED}&amp;quot; &amp;quot;${SUMMARY_MIN_HOST}&amp;quot; &amp;quot;${SUMMARY_MIN_PORT}&amp;quot; &amp;quot;${SUMMARY_MIN_DATE}&amp;quot; &amp;quot;${SUMMARY_MIN_DIFF}&lt;br /&gt;
&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    elif [ ${SUMMARY_WILL_EXPIRE} -ne 0 ]&lt;br /&gt;
    then&lt;br /&gt;
        ${PRINTF} &amp;quot;%s certificate(s) will expire (%s:%s on %s)|days=%s\n&amp;quot; &amp;quot;${SUMMARY_WILL_EXPIRE}&amp;quot; &amp;quot;${SUMMARY_MIN_HOST}&amp;quot; &amp;quot;${SUMMARY_MIN_PORT}&amp;quot; &amp;quot;${SUMMARY_MIN_DATE}&amp;quot; &amp;quot;${SUMMARY_M&lt;br /&gt;
IN_DIFF}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#############################################################&lt;br /&gt;
# Purpose: Set returncode to value if current value is lower&lt;br /&gt;
# Arguments:&lt;br /&gt;
#   $1 -&amp;gt; New returncorde&lt;br /&gt;
#############################################################&lt;br /&gt;
set_returncode()&lt;br /&gt;
{&lt;br /&gt;
    if [ ${RETCODE} -lt ${1} ]&lt;br /&gt;
    then&lt;br /&gt;
        RETCODE=${1}&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
########################################################################&lt;br /&gt;
# Purpose: Set certificate counters and informations for nagios summary&lt;br /&gt;
# Arguments:&lt;br /&gt;
#   $1 -&amp;gt; Status of certificate (0: valid, 1: will expire, 2: expired)&lt;br /&gt;
#   $2 -&amp;gt; Hostname&lt;br /&gt;
#   $3 -&amp;gt; TCP Port&lt;br /&gt;
#   $4 -&amp;gt; Date when certificate will expire&lt;br /&gt;
#   $5 -&amp;gt; Days left until the certificate will expire&lt;br /&gt;
########################################################################&lt;br /&gt;
set_summary()&lt;br /&gt;
{&lt;br /&gt;
    if [ ${1} -eq 0 ]&lt;br /&gt;
    then&lt;br /&gt;
        SUMMARY_VALID=$((SUMMARY_VALID+1))&lt;br /&gt;
&lt;br /&gt;
    elif [ ${1} -eq 1 ]&lt;br /&gt;
    then&lt;br /&gt;
        SUMMARY_WILL_EXPIRE=$((SUMMARY_WILL_EXPIRE+1))&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
        SUMMARY_EXPIRED=$((SUMMARY_EXPIRED+1))&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    if [ ${5} -lt ${SUMMARY_MIN_DIFF} ] || [ ${SUMMARY_MIN_DIFF} -eq 0 ]&lt;br /&gt;
    then&lt;br /&gt;
        SUMMARY_MIN_DATE=${4}&lt;br /&gt;
        SUMMARY_MIN_DIFF=${5}&lt;br /&gt;
        SUMMARY_MIN_HOST=${2}&lt;br /&gt;
        SUMMARY_MIN_PORT=${3}&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
##########################################&lt;br /&gt;
# Purpose: Describe how the script works&lt;br /&gt;
# Arguments:&lt;br /&gt;
#   None&lt;br /&gt;
##########################################&lt;br /&gt;
usage()&lt;br /&gt;
{&lt;br /&gt;
    echo &amp;quot;Usage: $0 [ -e email address ] [-E sender email address] [ -x days ] [-q] [-a] [-b] [-h] [-i] [-n] [-N] [-v]&amp;quot;&lt;br /&gt;
    echo &amp;quot;       { [ -s common_name ] &amp;amp;&amp;amp; [ -p port] } || { [ -f cert_file ] } || { [ -c cert file ] } || { [ -d cert dir ] }&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -a                : Send a warning message through E-mail&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -b                : Will not print header&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -c cert file      : Print the expiration date for the PEM or PKCS12 formatted certificate in cert file&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -d cert directory : Print the expiration date for the PEM or PKCS12 formatted certificates in cert directory&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -e E-mail address : E-mail address to send expiration notices&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -E E-mail sender  : E-mail address of the sender&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -f cert file      : File with a list of FQDNs and ports&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -h                : Print this screen&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -i                : Print the issuer of the certificate&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -k password       : PKCS12 file password&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -n                : Run as a Nagios plugin&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -N                : Run as a Nagios plugin and output one line summary (implies -n, requires -f or -d)&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -p port           : Port to connect to (interactive mode)&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -s commmon name   : Server to connect to (interactive mode)&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -t type           : Specify the certificate type&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -q                : Don't print anything on the console&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -v                : Specify a specific protocol version to use (tls, ssl2, ssl3)&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -V                : Only print validation data&amp;quot;&lt;br /&gt;
    echo &amp;quot;  -x days           : Certificate expiration interval (eg. if cert_date &amp;lt; days)&amp;quot;&lt;br /&gt;
    echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
##########################################################################&lt;br /&gt;
# Purpose: Connect to a server ($1) and port ($2) to see if a certificate&lt;br /&gt;
#          has expired&lt;br /&gt;
# Arguments:&lt;br /&gt;
#   $1 -&amp;gt; Server name&lt;br /&gt;
#   $2 -&amp;gt; TCP port to connect to&lt;br /&gt;
##########################################################################&lt;br /&gt;
check_server_status() {&lt;br /&gt;
&lt;br /&gt;
    if [ &amp;quot;_${2}&amp;quot; = &amp;quot;_smtp&amp;quot; -o &amp;quot;_${2}&amp;quot; = &amp;quot;_25&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        TLSFLAG=&amp;quot;-starttls smtp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    elif [ &amp;quot;_${2}&amp;quot; = &amp;quot;_ftp&amp;quot; -o &amp;quot;_${2}&amp;quot; = &amp;quot;_21&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        TLSFLAG=&amp;quot;-starttls ftp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    elif [ &amp;quot;_${2}&amp;quot; = &amp;quot;_pop3&amp;quot; -o &amp;quot;_${2}&amp;quot; = &amp;quot;_110&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        TLSFLAG=&amp;quot;-starttls pop3&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    elif [ &amp;quot;_${2}&amp;quot; = &amp;quot;_imap&amp;quot; -o &amp;quot;_${2}&amp;quot; = &amp;quot;_143&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        TLSFLAG=&amp;quot;-starttls imap&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    elif [ &amp;quot;_${2}&amp;quot; = &amp;quot;_submission&amp;quot; -o &amp;quot;_${2}&amp;quot; = &amp;quot;_587&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        TLSFLAG=&amp;quot;-starttls smtp -port ${2}&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
        TLSFLAG=&amp;quot;&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    if [ &amp;quot;${VERSION}&amp;quot; != &amp;quot;&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        VER=&amp;quot;-${VERSION}&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    if [ &amp;quot;${TLSSERVERNAME}&amp;quot; = &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
         TLSFLAG=&amp;quot;${TLSFLAG} -servername $1&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    echo &amp;quot;&amp;quot; | ${OPENSSL} s_client -crlf ${VER} -connect ${1}:${2} ${TLSFLAG} 2&amp;gt; ${ERROR_TMP} 1&amp;gt; ${CERT_TMP}&lt;br /&gt;
&lt;br /&gt;
    if ${GREP} -i &amp;quot;Connection refused&amp;quot; ${ERROR_TMP} &amp;gt; /dev/null&lt;br /&gt;
    then&lt;br /&gt;
        prints ${1} ${2} &amp;quot;Connection refused&amp;quot; &amp;quot;Unknown&amp;quot;&lt;br /&gt;
        set_returncode 3&lt;br /&gt;
&lt;br /&gt;
    elif ${GREP} -i &amp;quot;No route to host&amp;quot; ${ERROR_TMP} &amp;gt; /dev/null&lt;br /&gt;
    then&lt;br /&gt;
        prints ${1} ${2} &amp;quot;No route to host&amp;quot; &amp;quot;Unknown&amp;quot;&lt;br /&gt;
        set_returncode 3&lt;br /&gt;
&lt;br /&gt;
    elif ${GREP} -i &amp;quot;gethostbyname failure&amp;quot; ${ERROR_TMP} &amp;gt; /dev/null&lt;br /&gt;
    then&lt;br /&gt;
        prints ${1} ${2} &amp;quot;Cannot resolve domain&amp;quot; &amp;quot;Unknown&amp;quot;&lt;br /&gt;
        set_returncode 3&lt;br /&gt;
&lt;br /&gt;
    elif ${GREP} -i &amp;quot;Operation timed out&amp;quot; ${ERROR_TMP} &amp;gt; /dev/null&lt;br /&gt;
    then&lt;br /&gt;
        prints ${1} ${2} &amp;quot;Operation timed out&amp;quot; &amp;quot;Unknown&amp;quot;&lt;br /&gt;
        set_returncode 3&lt;br /&gt;
&lt;br /&gt;
    elif ${GREP} -i &amp;quot;ssl handshake failure&amp;quot; ${ERROR_TMP} &amp;gt; /dev/null&lt;br /&gt;
    then&lt;br /&gt;
        prints ${1} ${2} &amp;quot;SSL handshake failed&amp;quot; &amp;quot;Unknown&amp;quot;&lt;br /&gt;
        set_returncode 3&lt;br /&gt;
&lt;br /&gt;
    elif ${GREP} -i &amp;quot;connect: Connection timed out&amp;quot; ${ERROR_TMP} &amp;gt; /dev/null&lt;br /&gt;
    then&lt;br /&gt;
        prints ${1} ${2} &amp;quot;Connection timed out&amp;quot; &amp;quot;Unknown&amp;quot;&lt;br /&gt;
        set_returncode 3&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
        check_file_status ${CERT_TMP} $1 $2&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#####################################################&lt;br /&gt;
### Check the expiration status of a certificate file&lt;br /&gt;
### Accepts three parameters:&lt;br /&gt;
###  $1 -&amp;gt; certificate file to process&lt;br /&gt;
###  $2 -&amp;gt; Server name&lt;br /&gt;
###  $3 -&amp;gt; Port number of certificate&lt;br /&gt;
#####################################################&lt;br /&gt;
check_file_status() {&lt;br /&gt;
&lt;br /&gt;
    CERTFILE=${1}&lt;br /&gt;
    HOST=${2}&lt;br /&gt;
    PORT=${3}&lt;br /&gt;
&lt;br /&gt;
    ### Check to make sure the certificate file exists&lt;br /&gt;
    if [ ! -r ${CERTFILE} ] || [ ! -s ${CERTFILE} ]&lt;br /&gt;
    then&lt;br /&gt;
        echo &amp;quot;ERROR: The file named ${CERTFILE} is unreadable or doesn't exist&amp;quot;&lt;br /&gt;
        echo &amp;quot;ERROR: Please check to make sure the certificate for ${HOST}:${PORT} is valid&amp;quot;&lt;br /&gt;
        set_returncode 3&lt;br /&gt;
        return&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    ### Grab the expiration date from the X.509 certificate&lt;br /&gt;
    if [ &amp;quot;${PKCSDBPASSWD}&amp;quot; != &amp;quot;&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        # Extract the certificate from the PKCS#12 database, and&lt;br /&gt;
        # send the informational message to /dev/null&lt;br /&gt;
        ${OPENSSL} pkcs12 -nokeys -in ${CERTFILE} \&lt;br /&gt;
                   -out ${CERT_TMP} -clcerts -password pass:${PKCSDBPASSWD} 2&amp;gt; /dev/null&lt;br /&gt;
&lt;br /&gt;
        # Extract the expiration date from the certificate&lt;br /&gt;
        CERTDATE=$(${OPENSSL} x509 -in ${CERT_TMP} -enddate -noout | \&lt;br /&gt;
                 ${SED} 's/notAfter\=//')&lt;br /&gt;
&lt;br /&gt;
        # Extract the issuer from the certificate&lt;br /&gt;
        CERTISSUER=$(${OPENSSL} x509 -in ${CERT_TMP} -issuer -noout | \&lt;br /&gt;
                   ${AWK} 'BEGIN {RS=&amp;quot;/&amp;quot; } $0 ~ /^O=/ \&lt;br /&gt;
                                 { print substr($0,3,17)}')&lt;br /&gt;
&lt;br /&gt;
        ### Grab the common name (CN) from the X.509 certificate&lt;br /&gt;
        COMMONNAME=$(${OPENSSL} x509 -in ${CERT_TMP} -subject -noout | \&lt;br /&gt;
                   ${SED} -e 's/.*CN=//' | \&lt;br /&gt;
                   ${SED} -e 's/\/.*//')&lt;br /&gt;
&lt;br /&gt;
        ### Grab the serial number from the X.509 certificate&lt;br /&gt;
        SERIAL=$(${OPENSSL} x509 -in ${CERT_TMP} -serial -noout | \&lt;br /&gt;
                   ${SED} -e 's/serial=//')&lt;br /&gt;
    else&lt;br /&gt;
        # Extract the expiration date from the ceriticate&lt;br /&gt;
        CERTDATE=$(${OPENSSL} x509 -in ${CERTFILE} -enddate -noout -inform ${CERTTYPE} | \&lt;br /&gt;
                 ${SED} 's/notAfter\=//')&lt;br /&gt;
&lt;br /&gt;
        # Extract the issuer from the certificate&lt;br /&gt;
        CERTISSUER=$(${OPENSSL} x509 -in ${CERTFILE} -issuer -noout -inform ${CERTTYPE} | \&lt;br /&gt;
                   ${AWK} 'BEGIN {RS=&amp;quot;/&amp;quot; } $0 ~ /^O=/ { print substr($0,3,17)}')&lt;br /&gt;
&lt;br /&gt;
        ### Grab the common name (CN) from the X.509 certificate&lt;br /&gt;
        COMMONNAME=$(${OPENSSL} x509 -in ${CERTFILE} -subject -noout -inform ${CERTTYPE} | \&lt;br /&gt;
                   ${SED} -e 's/.*CN=//' | \&lt;br /&gt;
                   ${SED} -e 's/\/.*//')&lt;br /&gt;
&lt;br /&gt;
        ### Grab the serial number from the X.509 certificate&lt;br /&gt;
        SERIAL=$(${OPENSSL} x509 -in ${CERTFILE} -serial -noout -inform ${CERTTYPE} | \&lt;br /&gt;
                   ${SED} -e 's/serial=//')&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    ### Split the result into parameters, and pass the relevant pieces to date2julian&lt;br /&gt;
    set -- ${CERTDATE}&lt;br /&gt;
    MONTH=$(getmonth ${1})&lt;br /&gt;
&lt;br /&gt;
    # Convert the date to seconds, and get the diff between NOW and the expiration date&lt;br /&gt;
    CERTJULIAN=$(date2julian ${MONTH#0} ${2#0} ${4})&lt;br /&gt;
    CERTDIFF=$(date_diff ${NOWJULIAN} ${CERTJULIAN})&lt;br /&gt;
&lt;br /&gt;
    if [ ${CERTDIFF} -lt 0 ]&lt;br /&gt;
    then&lt;br /&gt;
        if [ &amp;quot;${ALARM}&amp;quot; = &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
            send_mail ${SENDER} ${ADMIN} &amp;quot;Certificate for ${HOST} \&amp;quot;(CN: ${COMMONNAME})\&amp;quot; has expired!&amp;quot; \&lt;br /&gt;
                &amp;quot;The SSL certificate for ${HOST} \&amp;quot;(CN: ${COMMONNAME})\&amp;quot; has expired!&amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
&lt;br /&gt;
        prints ${HOST} ${PORT} &amp;quot;Expired&amp;quot; &amp;quot;${CERTDATE}&amp;quot; &amp;quot;${CERTDIFF}&amp;quot; &amp;quot;${CERTISSUER}&amp;quot; &amp;quot;${COMMONNAME}&amp;quot; &amp;quot;${SERIAL}&amp;quot;&lt;br /&gt;
        RETCODE_LOCAL=2&lt;br /&gt;
&lt;br /&gt;
    elif [ ${CERTDIFF} -lt ${WARNDAYS} ]&lt;br /&gt;
    then&lt;br /&gt;
        if [ &amp;quot;${ALARM}&amp;quot; = &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
            send_mail ${SENDER} ${ADMIN} &amp;quot;Certificate for ${HOST} \&amp;quot;(CN: ${COMMONNAME})\&amp;quot; will expire in ${WARNDAYS}-days or less&amp;quot; \&lt;br /&gt;
                &amp;quot;The SSL certificate for ${HOST} \&amp;quot;(CN: ${COMMONNAME})\&amp;quot; will expire on ${CERTDATE}&amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
        prints ${HOST} ${PORT} &amp;quot;Expiring&amp;quot; &amp;quot;${CERTDATE}&amp;quot; &amp;quot;${CERTDIFF}&amp;quot; &amp;quot;${CERTISSUER}&amp;quot; &amp;quot;${COMMONNAME}&amp;quot; &amp;quot;${SERIAL}&amp;quot;&lt;br /&gt;
        RETCODE_LOCAL=1&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
        prints ${HOST} ${PORT} &amp;quot;Valid&amp;quot; &amp;quot;${CERTDATE}&amp;quot; &amp;quot;${CERTDIFF}&amp;quot; &amp;quot;${CERTISSUER}&amp;quot; &amp;quot;${COMMONNAME}&amp;quot; &amp;quot;${SERIAL}&amp;quot;&lt;br /&gt;
        RETCODE_LOCAL=0&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
    set_returncode ${RETCODE_LOCAL}&lt;br /&gt;
    MIN_DATE=$(echo ${CERTDATE} | ${AWK} '{ print $1, $2, $4 }')&lt;br /&gt;
    set_summary ${RETCODE_LOCAL} ${HOST} ${PORT} &amp;quot;${MIN_DATE}&amp;quot; ${CERTDIFF}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#################################&lt;br /&gt;
### Start of main program&lt;br /&gt;
#################################&lt;br /&gt;
while getopts abinNv:e:E:f:c:d:hk:p:s:t:qx:V option&lt;br /&gt;
do&lt;br /&gt;
    case &amp;quot;${option}&amp;quot;&lt;br /&gt;
    in&lt;br /&gt;
        a) ALARM=&amp;quot;TRUE&amp;quot;;;&lt;br /&gt;
        b) NOHEADER=&amp;quot;TRUE&amp;quot;;;&lt;br /&gt;
        c) CERTFILE=${OPTARG};;&lt;br /&gt;
        d) CERTDIRECTORY=${OPTARG};;&lt;br /&gt;
        e) ADMIN=${OPTARG};;&lt;br /&gt;
	E) SENDER=${OPTARG};;&lt;br /&gt;
        f) SERVERFILE=$OPTARG;;&lt;br /&gt;
        h) usage&lt;br /&gt;
           exit 1;;&lt;br /&gt;
        i) ISSUER=&amp;quot;TRUE&amp;quot;;;&lt;br /&gt;
        k) PKCSDBPASSWD=${OPTARG};;&lt;br /&gt;
        n) NAGIOS=&amp;quot;TRUE&amp;quot;;;&lt;br /&gt;
        N) NAGIOS=&amp;quot;TRUE&amp;quot;&lt;br /&gt;
           NAGIOSSUMMARY=&amp;quot;TRUE&amp;quot;;;&lt;br /&gt;
        p) PORT=$OPTARG;;&lt;br /&gt;
        s) HOST=$OPTARG;;&lt;br /&gt;
        t) CERTTYPE=$OPTARG;;&lt;br /&gt;
        q) QUIET=&amp;quot;TRUE&amp;quot;;;&lt;br /&gt;
        v) VERSION=$OPTARG;;&lt;br /&gt;
        V) VALIDATION=&amp;quot;TRUE&amp;quot;;;&lt;br /&gt;
        x) WARNDAYS=$OPTARG;;&lt;br /&gt;
       \?) usage&lt;br /&gt;
           exit 1;;&lt;br /&gt;
    esac&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
### Check to make sure a openssl utility is available&lt;br /&gt;
if [ ! -f ${OPENSSL} ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;ERROR: The openssl binary does not exist in ${OPENSSL}.&amp;quot;&lt;br /&gt;
    echo &amp;quot;FIX: Please modify the \${OPENSSL} variable in the program header.&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
### Check to make sure a date utility is available&lt;br /&gt;
if [ ! -f ${DATE} ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;ERROR: The date binary does not exist in ${DATE} .&amp;quot;&lt;br /&gt;
    echo &amp;quot;FIX: Please modify the \${DATE} variable in the program header.&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
### Check to make sure a grep and find utility is available&lt;br /&gt;
if [ ! -f ${GREP} ] || [ ! -f ${FIND} ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;ERROR: Unable to locate the greb and find binary.&amp;quot;&lt;br /&gt;
    echo &amp;quot;FIX: Please modify the \${GREP} and \${FIND} variables in the program header.&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
### Check to make sure the mktemp and printf utilities are available&lt;br /&gt;
if [ ! -f ${MKTEMP} ] || [ ! -f ${PRINTF} ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;ERROR: Unable to locate the mktemp or printf binary.&amp;quot;&lt;br /&gt;
    echo &amp;quot;FIX: Please modify the \${MKTEMP} and \${PRINTF} variables in the program header.&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
### Check to make sure the sed and awk binaries are available&lt;br /&gt;
if [ ! -f ${SED} ] || [ ! -f ${AWK} ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;ERROR: Unable to locate the sed or awk binary.&amp;quot;&lt;br /&gt;
    echo &amp;quot;FIX: Please modify the \${SED} and \${AWK} variables in the program header.&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
### Check to make sure a mail client is available it automated notifications are requested&lt;br /&gt;
if [ &amp;quot;${ALARM}&amp;quot; = &amp;quot;TRUE&amp;quot; ] &amp;amp;&amp;amp; [ ! -f ${MAIL} ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;ERROR: You enabled automated alerts, but the mail binary could not be found.&amp;quot;&lt;br /&gt;
    echo &amp;quot;FIX: Please modify the ${MAIL} variable in the program header.&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Send along the servername when TLS is used&lt;br /&gt;
if ${OPENSSL} s_client -help 2&amp;gt;&amp;amp;1 | grep '-servername' &amp;gt; /dev/null&lt;br /&gt;
then&lt;br /&gt;
    TLSSERVERNAME=&amp;quot;TRUE&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    TLSSERVERNAME=&amp;quot;FALSE&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Place to stash temporary files&lt;br /&gt;
CERT_TMP=$($MKTEMP /var/tmp/cert.XXXXXX)&lt;br /&gt;
ERROR_TMP=$($MKTEMP /var/tmp/error.XXXXXX)&lt;br /&gt;
&lt;br /&gt;
### Baseline the dates so we have something to compare to&lt;br /&gt;
MONTH=$(${DATE} &amp;quot;+%m&amp;quot;)&lt;br /&gt;
DAY=$(${DATE} &amp;quot;+%d&amp;quot;)&lt;br /&gt;
YEAR=$(${DATE} &amp;quot;+%Y&amp;quot;)&lt;br /&gt;
NOWJULIAN=$(date2julian ${MONTH#0} ${DAY#0} ${YEAR})&lt;br /&gt;
&lt;br /&gt;
### Touch the files prior to using them&lt;br /&gt;
if [ ! -z &amp;quot;${CERT_TMP}&amp;quot; ] &amp;amp;&amp;amp; [ ! -z &amp;quot;${ERROR_TMP}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    touch ${CERT_TMP} ${ERROR_TMP}&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;ERROR: Problem creating temporary files&amp;quot;&lt;br /&gt;
    echo &amp;quot;FIX: Check that mktemp works on your system&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
### If a HOST and PORT were passed on the cmdline, use those values&lt;br /&gt;
if [ &amp;quot;${HOST}&amp;quot; != &amp;quot;&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;${PORT}&amp;quot; != &amp;quot;&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    print_heading&lt;br /&gt;
    check_server_status &amp;quot;${HOST}&amp;quot; &amp;quot;${PORT}&amp;quot;&lt;br /&gt;
    print_summary&lt;br /&gt;
&lt;br /&gt;
### If a file is passed to the &amp;quot;-f&amp;quot; option on the command line, check&lt;br /&gt;
### each certificate or server / port combination in the file to see if&lt;br /&gt;
### they are about to expire&lt;br /&gt;
elif [ -f &amp;quot;${SERVERFILE}&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    print_heading&lt;br /&gt;
&lt;br /&gt;
    IFS=$'\n'&lt;br /&gt;
    for LINE in `egrep -v '(^#|^$)' ${SERVERFILE}`&lt;br /&gt;
    do&lt;br /&gt;
        HOST=${LINE%% *}&lt;br /&gt;
        PORT=${LINE#* }&lt;br /&gt;
        IFS=&amp;quot; &amp;quot;&lt;br /&gt;
        if [ &amp;quot;$PORT&amp;quot; = &amp;quot;FILE&amp;quot; ]&lt;br /&gt;
        then&lt;br /&gt;
            check_file_status ${HOST} &amp;quot;FILE&amp;quot; &amp;quot;${HOST}&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
            check_server_status &amp;quot;${HOST}&amp;quot; &amp;quot;${PORT}&amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
    done&lt;br /&gt;
    IFS=${OLDIFS}&lt;br /&gt;
    print_summary&lt;br /&gt;
&lt;br /&gt;
### Check to see if the certificate in CERTFILE is about to expire&lt;br /&gt;
elif [ &amp;quot;${CERTFILE}&amp;quot; != &amp;quot;&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    print_heading&lt;br /&gt;
    check_file_status ${CERTFILE} &amp;quot;FILE&amp;quot; &amp;quot;${CERTFILE}&amp;quot;&lt;br /&gt;
    print_summary&lt;br /&gt;
&lt;br /&gt;
### Check to see if the certificates in CERTDIRECTORY are about to expire&lt;br /&gt;
elif [ &amp;quot;${CERTDIRECTORY}&amp;quot; != &amp;quot;&amp;quot; ] &amp;amp;&amp;amp; (${FIND} -L ${CERTDIRECTORY} -type f &amp;gt; /dev/null 2&amp;gt;&amp;amp;1)&lt;br /&gt;
then&lt;br /&gt;
    print_heading&lt;br /&gt;
    for FILE in `${FIND} -L ${CERTDIRECTORY} -type f`; do&lt;br /&gt;
        check_file_status ${FILE} &amp;quot;FILE&amp;quot; &amp;quot;${FILE}&amp;quot;&lt;br /&gt;
    done&lt;br /&gt;
    print_summary&lt;br /&gt;
&lt;br /&gt;
### There was an error, so print a detailed usage message and exit&lt;br /&gt;
else&lt;br /&gt;
    usage&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
### Remove the temporary files&lt;br /&gt;
if [ $DEBUG == 1 ]&lt;br /&gt;
then&lt;br /&gt;
    echo &amp;quot;DEBUG: Certificate temporary file:&amp;quot;&lt;br /&gt;
    cat ${CERT_TMP}&lt;br /&gt;
    echo &amp;quot;DEBUG: Runtime information file:&amp;quot;&lt;br /&gt;
    cat ${ERROR_TMP}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
rm -f ${CERT_TMP} ${ERROR_TMP}&lt;br /&gt;
&lt;br /&gt;
### Exit with a success indicator&lt;br /&gt;
if [ &amp;quot;${NAGIOS}&amp;quot; = &amp;quot;TRUE&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
    exit $RETCODE&lt;br /&gt;
else&lt;br /&gt;
    exit 0&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>George2</name></author>	</entry>

	</feed>