Reputation: 15
how do i pass variable (missing file) $file from a script to my python email script in the body message. script.sh
#!/bin/bash
file = abc.txt
echo "the following" ${file} "are missing"
pythonEmail.py
pythonEmail.py
#!/usr/bin/python
import smtplib
sender = '[email protected]'
receivers = ['[email protected]']
message = """From: myself<[email protected]>
To: [email protected]'
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")
Upvotes: 0
Views: 720
Reputation: 228
This is not much more than what @Haxiel commented:
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 = '[email protected]'
receivers = ['[email protected]']
message = """\
From: myself<[email protected]>
To: [email protected]
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")
Upvotes: 1