繁体   English   中英

在 linux 的 mailx 命令的邮件中的邮件正文中添加 .txt 文件的内容

[英]adding the .txt file's content in the body of the message in the mail of mailx command in linux

我已经编写了一个脚本,我在其中存储了使用 cpu 最大内存的前 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"

这个“subject”、“from”、“also_to”、“to”是一些变量,并且在 shell 脚本中定义了实际的 mailid。

当我收到邮件时,我会以非常粗略的顺序收到内容,如下图所示。 那封邮件的照片

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

您正在滥用-a选项。 您应该使用它来添加邮件 header ( Header: value ),而不是像您一样添加一个单词“ALERT”。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM