No pude hacer funcionar el script, así que armé uno diferente aquí
#!/usr/local/bin/python
# Usage
# python utils/multi.py /path/to/cloud.cfg:text/cloud-config /path/to/script.sh:text/x-shellscript
import sys
import email
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
if len(sys.argv) == 1:
print("%s input-file:type ..." % (sys.argv[0]))
sys.exit(1)
combined_message = MIMEMultipart()
for i in sys.argv[1:]:
(filename, format_type) = i.split(":", 1)
with open(filename) as fh:
contents = fh.read()
sub_message = MIMEText(contents, format_type, sys.getdefaultencoding())
sub_message.add_header('Content-Disposition', 'attachment; file name="%s"' % (filename))
combined_message.attach(sub_message)
msg = email.message_from_string(combined_message.as_string())
for part in msg.walk():
if part.get_content_maintype() == 'text':
if part['Content-Transfer-Encoding'] in {'quoted-printable', 'base64'}:
payload = part.get_payload(decode=True)
del part['Content-Transfer-Encoding']
part.set_payload(payload)
email.encoders.encode_7or8bit(part)
# Send the modified message to stdout
print(msg.as_bytes().decode(encoding='UTF-8'))
Fuentes:
StackOverflow Question
CloudInit Docks