Compare the dates and send mail

Hi Guys,

I am new to this fourm. Need your help to complete my requirment.

Below is my requirment.

Have to check expiry of the certificate. Compare the certificate expiry date with current date. If the difference is less than 30 days, need to send mail.

#!/usr/bin/ksh
file="sslexpiry" #the file where you keep your string expiry date

name=$(cat "$file")        #the output of 'cat $file' is assigned to the $name variable
 
date > todate.ext #the file where you keep current date value

file1="todate.ext"  #the file where you keep your string current date

todaydate=$(cat "$file1") #the output of 'cat $file1' is assigned to the $todaydate variable
 
 
echo $name
echo $todaydate

---
I can print the dates as below

Fri Apr 10 18:59:59 CDT 2015
Thu Feb 19 18:50:52 CST 2015

--
Now i have to count the number of days between these two dates. After that need to sent mail if this value is less than 30.

Could you please help me to complete the script.

Thanks,
Ramesh

How is the file sslexpiry created?

You probably have to cheat and use something like perl or php. The following might do:

days=`perl -e 'use Date::Parse; print int((str2time($ARGV[1])-str2time($ARGV[0]))/86400);' "$name" "$todaydate"`
if [ "$days" -lt 30 ]; then
   echo "send mail..."
fi

If you have a fancy version of the date command like on linux you can also do the following:

days=$(( (`date --date="$name" +%s` - `date --date="$todaydate"  +%s`)/86400 ))
if [ "$days" -lt 30 ]; then
   echo "send mail..."
fi