我需要在bash脚本中包括以下python脚本。
如果bash脚本成功结束,则需要执行以下脚本:
#!/usr/bin/python
from smtplib import SMTP
import datetime
debuglevel = 0
smtp = SMTP()
smtp.set_debuglevel(debuglevel)
smtp.connect('192.168.75.1', 25)
smtp.login('my_mail', 'mail_passwd')
from_addr = "My Name <my_mail@192.168.75.1>"
to_addr = "<my_mail@192.168.75.1"
subj = "Process completed"
date = datetime.datetime.now().strftime( "%d/%m/%Y %H:%M" )
#print (date)
message_text = "Hai..\n\nThe process completed."
msg = "From: %s\nTo: %s\nSubject: %s\nDate: %s\n\n%s" % ( from_addr, to_addr, subj, date, message_text )
smtp.sendmail(from_addr, to_addr, msg)
smtp.quit()
为什么要“包含”它?为什么不运行它呢?
—
terdon
从python调用bash脚本
—
Costas 2015年
import os
os.system ("./script.sh")
script.sh && python script.py
?