<p>Thanks for this. I'm forwarding this to my Dad as he is currently learning python also.</p>
<div class="gmail_quote">On Nov 18, 2011 8:22 AM, "David Tomaschik" <<a href="mailto:david@systemoverlord.com">david@systemoverlord.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
X = "SomeValue","SomeOtherValue" creates a tuple. It does NOT do string<br>
concatenation. + will do concatenation, and is fine to use for one-time<br>
concatenation. (''.join(list) is better for large quantities.)<br>
<br>
Rather than os.getenv('HOSTNAME') consider using socket.gethostname().<br>
It doesn't require that your runtime environment have the HOSTNAME<br>
variable set correctly. (Which it often is not from cron or other<br>
system-level processes.)<br>
<br>
Other than that, see Richard's email.<br>
<br>
David<br>
<br>
<br>
On 11/17/2011 09:47 PM, Chuck Payne wrote:<br>
> Guys,<br>
><br>
> I need a mentor. I am trying to teach myself Python. I need to create<br>
> a few script to monitor my servers. But I am having issue with the<br>
> e-mail part of my script<br>
><br>
> What I want it to do it send me alert with the host name in the<br>
> Subject and Body, but I am either getting syntax error or when it does<br>
> work I get None. How can I pass the hostname?<br>
><br>
><br>
> Here my script<br>
><br>
> =============start script=============<br>
><br>
> #!/usr/bin/python<br>
><br>
> import os, smtplib<br>
> system_name = os.getenv('HOSTNAME')<br>
><br>
><br>
> SERVER = localhost<br>
><br>
> FROM = "<a href="mailto:me@abc.com">me@abc.com</a>"<br>
> TO = ["<a href="mailto:you@nbc.com">you@nbc.com</a>"]<br>
><br>
> SUBJECT = "Mail from",os.getenv('HOSTNAME')<br>
SUBJECT = "Mail from "+os.getenv('HOSTNAME')<br>
><br>
> TEXT = "This message is from",os.getenv('HOSTNAME')<br>
TEXT = "This message is from ",os.getenv('HOSTNAME')<br>
><br>
> message = """\<br>
> From: %s<br>
> To: %s<br>
> Subject: %s<br>
><br>
> %s<br>
> """ % (FROM, ", ".join(TO), SUBJECT, TEXT)<br>
><br>
> # Send message<br>
><br>
> server = smtplib.STMP(SERVER)<br>
> server.sendmail(FROM, TO, message)<br>
> server.quit()<br>
><br>
> =============end script=============<br>
<br>
<br>
--<br>
David Tomaschik, RHCE, LPIC-1<br>
System Administrator/Open Source Advocate<br>
OpenPGP: 0x5DEA789B<br>
<a href="http://systemoverlord.com" target="_blank">http://systemoverlord.com</a><br>
<a href="mailto:david@systemoverlord.com">david@systemoverlord.com</a><br>
_______________________________________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
</blockquote></div>