linux - 邮件命令行为不当

标签 linux shell

我编写了 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命令没有找到用户名,会发生什么情况,它会向该域的所有用户发送邮件吗?

如果您需要更多详细信息,我可以给您,因为我认为这似乎是我的脚本或邮件命令中的错误。

请回复

提前谢谢您。

最佳答案

一个问题是您如何尝试分配DATAheredoc 可以使内容更具可读性并防止多行字符串出现格式问题。

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/

相关文章:

linux - 无法使用 OpenLDAP 用户登录 Moodle

android - Git 预提交钩子(Hook)运行 lint 检查?

linux - 如何解析shell脚本中的以下内容?

linux - 在 bash 中替换/更新文本文档中的列值

linux - 如何从顶级目录之外运行 Flask 应用程序?

shell - POSIX shell 中是否需要 `command -v` 选项?豪华符合 POSIX 吗?

bash - Unix 使用 comm 比较两个 CSV 文件

shell - 用于将 IPv6 地址转换为数字(或字符串)的大型 CSV 文件的脚本

c++ - C++ 中 gettimeofday() 的最佳替代库是什么?

linux - 在 Linux 中对文件具有可执行权限有哪些安全风险?