The scope of the shell/perl script is to read the input text file. Validate the expiry date of each

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each certificate and send the mail to the user. The user takes action to add the new certificate to the storage file and user owns the responsibility to update the input text file with the new certificate details

Logic Requirement 1]

Write a shell/perl script to retrieve the data line by line from input file and compare the current date with the expiry date. If the validated difference in days is less than 7 days. The script must generate the email from the system/server and send the report to the end users.

Sample Data

server name | certificate name | start date | expiry date
cce-l3-na.lexington.ibm.com | verisign_class_3ppca | 11/07/2006  19:00:00 | 7/16/36 7:59 PM
cce-l3-na.lexington.ibm.com | wwwbeta335 | 5/17/07 6:38 PM | 8/16/11 6:38 PM
cce-l3-na.lexington.ibm.com | wi | 10/22/06 9:37 PM | 10/18/26 9:37 PM
cce-l3-na.lexington.ibm.com | verisignbluepages | 11/07/2006  19:00:00 | 7/16/36 7:59 PM
cce-l3-na.lexington.ibm.com | epricerjai | 05/08/2007  13:08:00 | 08/07/2010  13:08:00
cce-l3-na.lexington.ibm.com | ccel3na2011 | 03/02/2011  05:26:00 | 11/27/13 5:26 AM
cce-l3-na.lexington.ibm.com | entrustclientca | 10/12/1999  15:24:00 | 10/12/2019  15:54:00
cce-l3-na.lexington.ibm.com | verisignclass3g2ca | 5/17/98 8:00 PM | 08/01/2028  19:59:00
cce-l3-na.lexington.ibm.com | thawtepersonalbasicca | 12/31/95 7:00 PM | 12/31/20 6:59 PM

Let us assume - The current date is 8/12/11 and expiry date of the certificate is 8/16/11. In this example the difference between the expiry date and the current date is less than 7 days. So, the script must pick up this line data, design the mail as in the Email-example attached below and send the mail to the user. The date format is mm/dd/yy.

Note: If there are multiple certificates getting expired in the week, notify all the certificate and server details in the mail.

---------- Post updated at 09:01 AM ---------- Previous update was at 09:00 AM ----------

Please help urgently

What have you tried so far, and why does this look like an interview question?

1 Like

thanks for your reply pludi

This is the requirement I got from my management to validate the expiry date. Please help me

We would ask you again to show your own effort in resolving your own issue/task. We can only help you to help yourself....

Here's a starter pseudo-code:

  1. Get today date in the format: YYYYMMDD
  2. Convert the date in the last field of every line/record into the same YYYYMMDD format
  3. Subtract 2 from 1
  4. If the result of the subtraction is less than 4, tag the record/line for mailing
  5. Mail all the tagged records/line to a designated address.

What Operating System and version are you running?
What Shell do you use?
What version of "perl" (if any) do you have?

To read throug the file a line at a time:

#!/usr/bin/perl
open(my $cert_file, '<' , 'PATH_TO_FILE');
while(<$cert_file>){

To get the current time

@now=localtime(time); # see time_t structures to see how this can be turned into your desired format.

To extract the date (4th field) from the record

my ($host, $cert,$start,$end)=split / | /, $record);

Try stringing that lot together and come back with any issues you are having