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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting The scope of the shell/perl script is to read the input text file. Validate the expiry date of each
# 1  
Old 04-21-2011
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
Code:
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
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 04-21-2011 at 11:09 AM.. Reason: code tags, please!
# 2  
Old 04-21-2011
What have you tried so far, and why does this look like an interview question?
This User Gave Thanks to pludi For This Post:
# 3  
Old 04-21-2011
thanks for your reply pludi

This is the requirement I got from my management to validate the expiry date. Please help me
# 4  
Old 04-21-2011
Quote:
Originally Posted by casmo
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.

Last edited by vgersh99; 04-21-2011 at 11:43 AM..
# 5  
Old 04-21-2011
What Operating System and version are you running?
What Shell do you use?
What version of "perl" (if any) do you have?
# 6  
Old 04-21-2011
To read throug the file a line at a time:
Code:
#!/usr/bin/perl
open(my $cert_file, '<' , 'PATH_TO_FILE');
while(<$cert_file>){

To get the current time
Code:
@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
Code:
my ($host, $cert,$start,$end)=split / | /, $record);

Try stringing that lot together and come back with any issues you are having
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

2. UNIX for Dummies Questions & Answers

Inserting shell script input data automatically from a text file

Dear experts, I am new to linux programming. I have a shell script which i should run it on all my samples. I only define input and out put for this script. The inputs are 3 numbers(coordination numbers) which are available in a series of text file. Since i have a lots of samples, it takes a... (5 Replies)
Discussion started by: mohamadreza
5 Replies

3. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

4. Shell Programming and Scripting

[Solved] Read and validate input arguments

Hi, I need to get input arguments, as well as validate them. This is how I'm reading them: #!/bin/bash args="$@" # save arguments to variable ## Read input arguments, if so while ; do case $1 in -v | --verbose ) verbose=true;; -z | --gzip ) compression="gz";; ... (3 Replies)
Discussion started by: AlbertGM
3 Replies

5. Shell Programming and Scripting

Need script to validate file according to date

Hi All, I am very new to unix and just started to work with unix and shell scripting.I have a query anyone help would be much appreciated I am using sun solaris OS I want to validate a file according to its date and if validate successful then it would write the file name,size,date and... (3 Replies)
Discussion started by: sv0081493
3 Replies

6. Shell Programming and Scripting

need shell or Perl script to read multiple input

I need shell 0r Perl script to read multiple input and do something and come out example: echo “ enter the host names separated by space “ read servers foreach @servers { do do something done} Here host names like host1 host2 host3 . . . . . . . so on Please help me... (8 Replies)
Discussion started by: sreedhargouda
8 Replies

7. Shell Programming and Scripting

How to read the data from the text file in shell script?

I am having one text file and i need to read that data from my shell script. I will expain you the scenario: Script look like: For name type 1: For age type 2: For Salary type3: echo "Enter the input:" read the data if input is 1 then go to the Text file and print the... (2 Replies)
Discussion started by: dineshmurs
2 Replies

8. Shell Programming and Scripting

Expiry date of shell script

Hello folks, I have question about my expiry of shell script, today date is 2009-11-11, i will have to deploy a script today, how i should setup that my script will not work after 2010-05-11, Between if someone will change the date of server then script will again not work, please give... (3 Replies)
Discussion started by: learnbash
3 Replies

9. Shell Programming and Scripting

Need to validate a date input format

Hi all, I have a shell script(K shell) which takes a date as input. i want the input to be in DD-MM-YYYY format. Can i enforce such a format of input string using just one line of code? OR do i need to parse the input date into different components and test them using Case statements... (2 Replies)
Discussion started by: rajugp1
2 Replies

10. Shell Programming and Scripting

How to input username on text file into finger command on shell script

I'm trying to clean up my server and I have the list of some "special" users stored on the text file like this Now I want to write a shell script to finger all of them so I can have some kind of ideas who they are but here comes the problem....I completely forgot how to do it with shell... (3 Replies)
Discussion started by: Micz
3 Replies
Login or Register to Ask a Question