向用户发送电子邮件通知,同时指定用户的姓名和证书的到期日期

向用户发送电子邮件通知,同时指定用户的姓名和证书的到期日期

我想向证书即将过期的用户发送电子邮件通知。下面的代码允许我向 MySQL 中选择的每个电子邮件地址发送电子邮件。我想同时选择电子邮件和到期日期来发送通知。

#!/bin/bash
EMAIL_ADDRESS="mysql -N -uUser -pPassword database -e \
"SELECT email FROM table WHERE DATEDIFF(date_expiration, CURDATE()) <=30 AND date_expiration > CURDATE()" 
echo  "Hello! The expiration date of your certificate is [date_expiration] ,please follow the procedure to renew it" \
| mailx -A gmail -s "Certificate expiration date" $EMAIL_ADDRESS

答案1

#!/bin/bash
while read -r N E D ; do
    echo  "Hello $N, The expiration date of your certificate for $D is nearing, please renew it" \
    | mailx -A gmail -s "Certificate expiration date" "$N <$E>"
done < <(mysql -N -uUser -pPassword database -e \
"SELECT name, email, domain FROM users, certs WHERE domain.user=user.id and DATEDIFF(date_expiration, CURDATE()) <=30 AND date_expiration > CURDATE()" )

相关内容