I'm getting weird NameError! i have a bash script who checks CPU status, puts it inside file (linux, btw), then executes python script who's doing the math, then runs another script that checks which core in working too hard, creates a file with the core number (so I can later check if the right core is still working too hard) and then sends mail if its the first time the core reaches over 90%.
Now, here's the problem! when i'm running the "SendMail.py" script (will add it below) i'm getting NameError: global name 'smtplib' is not defined. Yes, i've imported it. and when I run the script without the other script lunches it - everything works well and i'm getting my email!
so - here's my script... will be glad if anyone might help :)
Ofek.
#!/usr/bin/python
import os
import smtplib
with open("/linux/sendmail",'r') as nas_file:
success=nas_file.read()
print(success)
def send_mail(msg):
fromaddr = 'XXXXX'
toaddrs = 'XXXXX'
# Credentials (if needed)
username = 'XXXXX'
password = 'XXXXX'
# The actual mail send
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
return
if True:
send_mail(success)
Traceback:
Traceback (most recent call last):
File "cpu_check.py", line 51, in <module>
scancores()
File "cpu_check.py", line 35, in scancores
execfile("SendMail.py")
File "SendMail.py", line 25, in <module>
send_mail(success)
File "SendMail.py", line 18, in send_mail
server = smtplib.SMTP('smtp.gmail.com:587')
NameError: global name 'smtplib' is not defined