python - 我正在尝试使用 shell 命令在 python 中发送邮件。但变量不会在脚本中被替换

标签 python bash email subprocess

import subprocess
to ='xxxx@fmr.com'
subject= 'hostname'
cmd= "cat /var/log | mailx -s 'swap is full on'+subject" +to
subprocess.Popen(cmd,shell=True)

如果我在主题前放置双引号,则 mailx 将第一个字符作为主题并将其他字符视为收件人并尝试向他们发送邮件。

--------------------cmd= "cat/var/log | mailx -s 'swap is full on'"+subject +to< 的输出/h1>

最佳答案

你能试试这个吗:

import subprocess
to ='xxxx@fmr.com'
cmd= "cat /var/log | mailx -s 'test' " + to
subprocess.Popen(cmd,shell=True)

关于python - 我正在尝试使用 shell 命令在 python 中发送邮件。但变量不会在脚本中被替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34915722/

相关文章:

python - 该程序中的某些进程是否可能比其他进程完成得更快?

bash - 使用 bash 更新属性文件中的版本号

python - 如何使用 bash 脚本退出 Django 开发服务器?

django - 从 Django 应用程序发送电子邮件

python - 导入错误 : cannot import name HTTPSHandler installing get-pip.

python - 在 Python 中表示集合中多个等效键的数据结构?

Python——递归字符串查找

linux - Bash : syntax error operand expected “=” , in assignment statement in a for loop

C# 发送群发邮件

html - Border-radius 没有显示在我的电子邮件表上