How to monitor certificate expiry date using a linux script
Hi,
I face a problem to compare time and date. I need to convert the format of the output of "date" command with the following default format: Mon Apr 27 02:29:57 EST 2009 to the following Format: Apr 27 02:29:57 2009 GMT The purpose of this is to design a script to monitor if a certificate expires or not. The latest format "Apr 27 02:29:57 2009 GMT" is the date format of the certificate which I cannot compare with "date". How can I compare if it is expired? can you help me please ? Thanks all in advance, Jef |
Try checking out `man convdate`. Put both in the form of seconds since the epoch, and then do a simple numerical comparison.
Alternatively, mon (http://mon.wiki.kernel.org/index.php/Main_Page) has a monitor module that checks web certs for expiration. With terms like "mon" and "monitor", that can be wickedly difficult to google. ;) So, I have to remember "kernel.org" to even find them, and then follow links from there or ask on their mailing list. However, I particularly like mon for its simplicity -- http://blogs.umass.edu/choogend/2007...nitoring-tool/ |
look to man date and use the [+Format....]
in the format you can use %Mon for month etc. |
Forget about comparing dates this way. Sooner or later it goes wrong because there is one character different or the time zone doesn't match.
Use: Code:
date -d "Mon Apr 27 02:29:57 EST 2009" +%s Code:
date -d "Apr 27 02:29:57 2009 GMT" +%s Code:
donald_pc:~$ diff=$(echo "$(date -d "Apr 27 02:29:57 2009 GMT" +%s) $(date -d "Mon Apr 27 02:29:57 EST 2009" +%s) - p" | dc) jlinkels |
Quote:
Thanks mate :) |
Quote:
|
Quote:
Thanks alot mate, |
All times are GMT -5. The time now is 05:23 PM. |