我编写了 shell 脚本来自动设置用户的配额。我有quota.csv,我曾经在其中获取用户名并向他们发送第一封邮件,然后为该用户设置配额。 当我执行该脚本时,邮件已发送至我们域的所有用户,这是不应该发生的。邮件应仅发送给quota.csv内可用的用户
下面是我的脚本
#!/bin/bash
#set -vx
DIR=/home/opr/administration/quotaset/
LOGFILE=setquota.log
DATA="Dear User,
\n \n \t Your account has been successfully created at Mailhost please take note of the following.
\n \n \t There is a phishing attempt (An email with the subject 'Tata Institute of
Fundamental Research Internet User' has been circulating.) to collect your
id and password of mailhost. This is not legitimate. Please do not disclose
it in any form to anybody even to Computer Centre staff.
If you are in doubt please call Computer Centre staff at 2121
\n \n -Raghavan"
EMAIL=@tifr.res.in
QuotaFILE=quota.csv
cd $DIR
QuotaFILE=`ls -1 quota.csv`
if [ -f "$QuotaFILE" ]
then
echo "Script started on `date`" >> $DIR/$LOGFILE
while read line
do
echo -e $DATA | mail -s "Welcome to TIFR Mailhost" -c "msagar@tifr.res.in" "$line$EMAIL"
edquota -p proto $line
done < $QuotaFILE
echo "Script Ended On `date`" >> $DIR/$LOGFILE
else
exit
fi
如果mail命令没有找到用户名,会发生什么情况,它会向该域的所有用户发送邮件吗?
如果您需要更多详细信息,我可以给您,因为我认为这似乎是我的脚本或邮件命令中的错误。
请回复
提前谢谢您。
最佳答案
一个问题是您如何尝试分配DATA
。 heredoc 可以使内容更具可读性并防止多行字符串出现格式问题。
DATA=$(cat<< EOF
Dear User,
Your account has been successfully created at Mailhost please take note
of the following.
There is a phishing attempt (An email with the subject 'Tata Institute of
Fundamental Research Internet User' has been circulating.) to collect your
id and password of mailhost. This is not legitimate. Please do not disclose
it in any form to anybody even to Computer Centre staff.
If you are in doubt please call Computer Centre staff at 2121
-Raghavan
EOF)
下一个:
QuotaFILE=`ls -1 quota.csv`
应该简单地是:
QuotaFILE=quota.csv
不知道 quota.csv
中的内容,您还应该使用以下方法防止转义序列的解释:
while read -r line
您还应该用大括号保护以下内容:
"$line$EMAIL"
更改为:
"${line}${EMAIL}"
最后,更重要的是,除非您的 mail
程序具有允许 @domain
代表向系统的所有用户发送邮件的特殊功能,否则您向 @domain
发送邮件的尝试将失败,因为 @domain
不是有效的电子邮件地址,smtp 主机可能无法确定是否应允许服务以及大量其他邮件 RFC 违规。
尝试更正,并验证您是否有允许发送到 @domain
的内容,如果没有,那就是您的问题。
关于linux - 邮件命令行为不当,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31199955/