I wrote code to read a file text with contents of expiration dates and products. The products expire in thirty days and each day an email message is send as a reminder of the number of days left before the license expires.
The code generates errors when executed .
Here is part of the code. Please see attachment:
# Convert date to check in seconds
current_date='date "+%s"'
#foo5.txt
expires=' /path/to/ foo5.txt
-noout -enddate | grep | awk '{print $1, $2, $3}''
date_to_check=date -d | awk -v expires="$expires" '{print $2 expires}'expires "+%s"'
#calculate the datediff
datediff='expr $date_to_check - $current_date'
#30 days left - send email: 30 days in seconds(2592000)
if [ 'expr $date_diff - 2592000' -gt 0 ]
then
echo | awk expires="$expires"'{print "30 days left. Product and Expiration date: " $1, $3 }'expires'| mail -s "Product Expiring" mary@rer.com
# 29 days left - send email- 29 days in seconds(2505600)
elif [ 'expr $date_diff - 2505600' -gt 0 ]
then
echo | awk expires="$expires"'{print "29 days left. Product and Expiration date: " $1, $3}'expires'| mail -s "Product Expiring" mary@rer.com
# 28 days left send email. 28 days in seconds(2419200)
elif [ 'expr $date_diff - 2419200' -gt 0 ]
then
echo | awk expires="$expires"'{print "28 days left. Product and Expiration date:" $1, $3}'expires'| mail -s "Product Expiring" mary@rer.com
# 27 days left - send email 27 days in seconds (233200)
elif [ 'expr $date_diff - 233200' -gt 0 ]
then
echo | awk expires="$expires"'{print "27 days left. Product and Expiration date:" $1, $3}'expires'| mail -s "Product Expiring" mary@rer.com
fi
foo5.txt : contents in foo5.txt are as follows:
B colb software 2015/11/30 30Nov2015
S/G 2015/10/30 30Oct2015
GH/Software 2015/11/30 30Nov2015
KP/software 2015/10/30 30Oct2015