将变量从脚本传递到我的 python 电子邮件脚本以在邮件中输出

Passing variable from a script to my python email script to be output in in mail under quotation

如何在正文中将变量(丢失的文件)$file 从脚本传递到我的 python 电子邮件脚本。 script.sh

#!/bin/bash
file = abc.txt
echo "the following" ${file} "are missing"
pythonEmail.py

pythonEmail.py

#!/usr/bin/python
import smtplib
sender = 'me@test.com'
receivers = ['you@test.com']
message = """From: myself<me@test.com>
To: you@test.com'
Subject: missing files
$file
"""
try:
   smtpObj = smtplib.SMTP("localhost")
   smtpObj.sendmail(sender, receivers, message)
   print ("Successfully sent email")
except SMTPException:
   print ("Error: unable to send email")

这与@Haxiel 评论的内容差不多:

script.sh:

#!/bin/bash
file=abc.txt
echo "the following" ${file} "are missing"
pythonEmail.py $file

pythonEmail.py:

#!/usr/bin/python
import smtplib
import sys

sender = 'me@test.com'
receivers = ['you@test.com']
message = """\
From: myself<me@test.com>
To: you@test.com
Subject: missing files

%s""" % (sys.argv[1])

try:
   smtpObj = smtplib.SMTP("localhost")
   smtpObj.sendmail(sender, receivers, message)
   print ("Successfully sent email")
except SMTPException:
   print ("Error: unable to send email")