python - succeed in script but fail in rc.local -
i write mail.py(use webpy) send me ip address of each machine.
#!/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 "-----------------------------------------------------------" i can receive email if 'python mail.py'.but when put in rc.local, can not receive email, message in deploy.log outputs [errno -2 ] name or service not known.
i puzzled output.
this might happen because path different when rc.local runs. specifically, web.sendmail might expect find sendmail in path, it's not there yet. see docs here.
the paths might specific system. debug dump things inside rc.local file such /tmp/rc.local.log , inspect when system up: e.g., env >>/tmp/rc.local.log.
note, if have multiple drives being mounted during startup, drive containing sendmail might not mounted yet @ point. pain deal with. double check, add mount >>/tmp/rc.local.log.
Comments
Post a Comment