LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-26-2009, 08:29 AM   #1
jefn
Member
 
Registered: Mar 2009
Posts: 37

Rep: Reputation: 15
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

Last edited by jefn; 04-26-2009 at 12:22 PM.
 
Old 04-26-2009, 01:38 PM   #2
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
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/
 
Old 04-26-2009, 03:38 PM   #3
Asy
LQ Newbie
 
Registered: May 2008
Location: The Netherlands
Distribution: Ubuntu
Posts: 25

Rep: Reputation: 16
look to man date and use the [+Format....]
in the format you can use %Mon for month etc.
 
Old 04-26-2009, 07:48 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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
and
Code:
date -d "Apr 27 02:29:57 2009 GMT" +%s
To get the time difference (or equality), use this expression:
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)
donald_pc:~$ echo $diff
-18000
The time difference is in seconds and 0 if there is no time difference. Note that these expression currently do not take DST into account, because I don't have tz_dsttime set on my computer. Maybe you should check that yourself on your own computer.

jlinkels
 
Old 04-27-2009, 04:36 AM   #5
jefn
Member
 
Registered: Mar 2009
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by choogendyk View Post
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/

Thanks mate
 
Old 04-27-2009, 04:36 AM   #6
jefn
Member
 
Registered: Mar 2009
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Asy View Post
look to man date and use the [+Format....]
in the format you can use %Mon for month etc.
Thanks mate
 
Old 04-27-2009, 04:37 AM   #7
jefn
Member
 
Registered: Mar 2009
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jlinkels View Post
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
and
Code:
date -d "Apr 27 02:29:57 2009 GMT" +%s
To get the time difference (or equality), use this expression:
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)
donald_pc:~$ echo $diff
-18000
The time difference is in seconds and 0 if there is no time difference. Note that these expression currently do not take DST into account, because I don't have tz_dsttime set on my computer. Maybe you should check that yourself on your own computer.

jlinkels
I think this is what I am looking for.

Thanks alot mate,
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
User login expiry date? geekgrl Linux - Security 7 07-04-2011 06:08 AM
Expiry date for users kapilbajpai88 Linux - Newbie 3 04-27-2009 02:46 PM
how to check the password expiry date of a user? binary_0011 Other *NIX 1 06-04-2008 01:37 AM
Terminal Command to find out expiry date on user accounts Caighil Linux - Newbie 3 02-29-2008 04:47 PM
Can I retrieve certificate expiry date from an openssl certificate (command line) davee Linux - Security 1 07-21-2006 10:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration