0
我编写mail.py(使用webpy)向我发送每台机器的IP地址。在脚本中成功但在rc.local中失败
#!/usr/bin/env python
#coding=utf-8
import web
def send_mail(send_to, subject, body, cc=None, bcc=None):
try:
web.config.smtp_server = 'xxxxx'
web.config.smtp_port = 25
web.config.smtp_username = 'xxx'
web.config.smtp_password = 'xxx'
web.config.smtp_starttls = True
send_from = 'xxx'
web.sendmail(send_from, send_to, subject, body, cc=cc, bcc=bcc)
return 1 #pass
except Exception, e:
print e
return -1 #fail
if __name__=='__main__':
print "in mail.py"
f=file('/home/spark/Desktop/ip.log')
f1=f.read()
f.close()
send_to = ['xxxx']
subject = 'xxxx'
body = 'ip:',f1
send_mail(send_to, subject, body)
rc.local中
bash deploy.sh &
exit 0
deploy.sh
#!/usr/bin/env
cd /home/spark/Desktop
python mail.py >>deploy.log
echo "-----------------------------------------------------------"
,如果我做“蟒蛇mail.py'.But我可以接收电子邮件,当我把它放在rc.local中,我无法收到电子邮件,部署日志输出中的消息 [Errno -2]名称或服务未知。
我对这个输出感到困惑。
我改变了web.config.smtp_server与IP地址,而不是域名,它的工作。我认为这个错误是因为一些配置和服务在rc.local过程中不可用。有用的链接是[sendmail](https://wiki.list.org/DOC/Mail%20delivery%20fails%20with%20%22(-2,%20'Name%20or%20service%20not%20known')%22 ,%20aka%20I%20am%20not%20receiving%20any%20notification%20messages%20from%20Mail) [http://support.microsoft.com/kb/23777121/why-am-i-getting-socket- gaierror-errno-2-from-python-httplib) – makeapp
[技巧来调试rc.local](http://stackoverflow.com/questions/7783341/run-script-with-rc-local-script-works-but-未在启动) – makeapp