我编写了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命令没有找到用户名会发生什么,它会向域的所有用户发送邮件吗?
如果你需要更多细节,我可以给你,因为我认为这似乎是我的脚本或邮件命令中的错误。
请回复
提前谢谢你。
答案 0 :(得分:0)
一个问题是您尝试分配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
的内容,如果没有,则表明您的问题。