[英]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.