【问题标题】:adding the .txt file's content in the body of the message in the mail of mailx command in linux在 linux 中 mailx 命令的邮件中添加 .txt 文件的内容到邮件正文中
【发布时间】:2021-08-10 13:53:01
【问题描述】:

我编写了一个脚本,我在其中存储了前 10 个进程的名称,这些进程使用了​​一个命令:

ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head >/etc/tmp/file.txt

现在我在 mailx 命令中附加此文件,以使用以下命令发送邮件,其正文作为内容:

echo -e "Warning, server memory is running low!\n\nFree memory: $free MB\n$file" | mailx -a "ALERT" -s "$subject" -r "$from" -c "$also_to" "$to"

this "subject" , "from", "also_to", "to" 是一些变量,并在 shell 脚本中定义了实际的 mailid。

当我收到邮件时,我会以非常粗略的顺序收到内容,如下图所示。that mail's pic

我希望文件的此内容采用正确的格式,或者如果我可以将此 txt 文件作为附件发送,我对使用 mailx 命令将文件作为附件发送但无济于事。

【问题讨论】:

    标签: linux server alert monitoring


    【解决方案1】:

    您误用了-a 选项。您应该使用它来添加邮件标题 (Header: value),而不是像您所做的那样添加单个单词“ALERT”。

    关于如何将文件作为附件发送,我通常使用-A 选项没有问题(最糟糕的是,我依稀记得有时我必须指定文件编码才能正确显示重音字符,但是你的 ASCII 文件不需要这个)

    【讨论】:

    • 我使用了 -A 但它不起作用,直接使用 -A 我们必须命名文件或提及该文件的整个路径。
    猜你喜欢
    • 1970-01-01
    • 2020-06-02
    • 2011-04-29
    • 2015-05-10
    • 2015-12-19
    • 2012-01-24
    • 1970-01-01
    • 1970-01-01
    • 2013-09-04
    相关资源
    最近更新 更多