This Script will send the reminder email 90 Days before the AMC Expires .
The Number of Days you can change by changing the NU Value . the email@domain.com should be replaced with your email id. The send-mail Path can be replaced by the send-mail path of the server.
There is need to create a Data file which will contain the Information for AMC of the Equipment. The input.txt format is shown below .
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#script for amc expiry email notification.
NU="90"
FROM="admin@domain.com"
#value1=$(echo $line| awk -F\ '{print $1}' input.txt)
#value2=$(echo $line| awk -F\ '{print $2}' input.txt)
#value3=$(echo $line| awk -F\ '{print $3}' input.txt)
DATEN=$(date +%s)
IFS="|"
while read -r value1 value2 value3
do
echo "value1 is " $value1
echo "value 2 is " $value2
echo "value 3 is " $value3
dat2=$(date -d "$value3" +'%Y%m%d')
echo "dat2 is expiry date "$dat2
DATE=$(date -d "$dat2" +%s)
echo "date for expiry in seconds " $DATE
echo "todays date in seconds is "$DATEN
DEADLINE=$(( (($DATE - $DATEN)) / 86400 ))
echo $DEADLINE
if [[ "$DEADLINE" -lt "$NU" ]]
then
MAIL_BODY="
Dear Team,
The "$value2" going to expires in "$DEADLINE" days
Regards,
AMC Team
.
"
echo "Subject: AMC / Warranty Alert" "$MAIL_BODY" | /opt/zimbra/postfix-2.10.3.2z/sbin/sendmail -t email@domain.com
fi
done < "/usr/bin/input.txt"
The input.txt file is shown below. Replace the Vendor_NAME AMC-Server and Serial Number Last is the date of AMC/Warranty/Subscription Expiry Date. Please put the file in /usr/bin folder with same name as input.txt
Vendor_NAME|AMC-Server/N:F8393993939333|YYYYMMDD
Vendor_NAME2|AMC-Server1/N:F8393993939333|YYYYMMDD
Vendor_NAME3|AMC-Server2/N:F8393993939333|YYYYMMDD
Vendor_NAME4|AMC-Server3/N:F8393993939333|YYYYMMDD
Vendor_NAME5|AMC-Storage4/N:F8393993939333|YYYYMMDD
Vendor_NAME|AMC-Router/N:F8393993939333|YYYYMMDD
Vendor_NAME|AMC-FIREWALL/N:F8393993939333|YYYYMMDD
Vendor_NAME|AMC-Software1/N:F8393993939333|YYYYMMDD
The Number of Days you can change by changing the NU Value . the email@domain.com should be replaced with your email id. The send-mail Path can be replaced by the send-mail path of the server.
There is need to create a Data file which will contain the Information for AMC of the Equipment. The input.txt format is shown below .
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#script for amc expiry email notification.
NU="90"
FROM="admin@domain.com"
#value1=$(echo $line| awk -F\ '{print $1}' input.txt)
#value2=$(echo $line| awk -F\ '{print $2}' input.txt)
#value3=$(echo $line| awk -F\ '{print $3}' input.txt)
DATEN=$(date +%s)
IFS="|"
while read -r value1 value2 value3
do
echo "value1 is " $value1
echo "value 2 is " $value2
echo "value 3 is " $value3
dat2=$(date -d "$value3" +'%Y%m%d')
echo "dat2 is expiry date "$dat2
DATE=$(date -d "$dat2" +%s)
echo "date for expiry in seconds " $DATE
echo "todays date in seconds is "$DATEN
DEADLINE=$(( (($DATE - $DATEN)) / 86400 ))
echo $DEADLINE
if [[ "$DEADLINE" -lt "$NU" ]]
then
MAIL_BODY="
Dear Team,
The "$value2" going to expires in "$DEADLINE" days
Regards,
AMC Team
.
"
echo "Subject: AMC / Warranty Alert" "$MAIL_BODY" | /opt/zimbra/postfix-2.10.3.2z/sbin/sendmail -t email@domain.com
fi
done < "/usr/bin/input.txt"
The input.txt file is shown below. Replace the Vendor_NAME AMC-Server and Serial Number Last is the date of AMC/Warranty/Subscription Expiry Date. Please put the file in /usr/bin folder with same name as input.txt
Vendor_NAME|AMC-Server/N:F8393993939333|YYYYMMDD
Vendor_NAME2|AMC-Server1/N:F8393993939333|YYYYMMDD
Vendor_NAME3|AMC-Server2/N:F8393993939333|YYYYMMDD
Vendor_NAME4|AMC-Server3/N:F8393993939333|YYYYMMDD
Vendor_NAME5|AMC-Storage4/N:F8393993939333|YYYYMMDD
Vendor_NAME|AMC-Router/N:F8393993939333|YYYYMMDD
Vendor_NAME|AMC-FIREWALL/N:F8393993939333|YYYYMMDD
Vendor_NAME|AMC-Software1/N:F8393993939333|YYYYMMDD
Comments
Post a Comment