[ale] Need help with a Python Script

Richard Bronosky Richard at Bronosky.com
Fri Nov 18 09:47:25 EST 2011


Thanks for this. I'm forwarding this to my Dad as he is currently learning
python also.
On Nov 18, 2011 8:22 AM, "David Tomaschik" <david at systemoverlord.com> wrote:

> X = "SomeValue","SomeOtherValue" creates a tuple.  It does NOT do string
> concatenation.  + will do concatenation, and is fine to use for one-time
> concatenation.  (''.join(list) is better for large quantities.)
>
> Rather than os.getenv('HOSTNAME') consider using socket.gethostname().
> It doesn't require that your runtime environment have the HOSTNAME
> variable set correctly.  (Which it often is not from cron or other
> system-level processes.)
>
> Other than that, see Richard's email.
>
> David
>
>
> On 11/17/2011 09:47 PM, Chuck Payne wrote:
> > Guys,
> >
> > I need a mentor.  I am trying to teach myself Python. I need to create
> > a few script to monitor my servers.  But I am having issue with the
> > e-mail part of my script
> >
> > What I want it to do it send me alert with the host name in the
> > Subject and Body, but I am either getting syntax error or when it does
> > work I get None.  How can I pass the hostname?
> >
> >
> > Here my script
> >
> > =============start script=============
> >
> > #!/usr/bin/python
> >
> > import os, smtplib
> > system_name = os.getenv('HOSTNAME')
> >
> >
> > SERVER = localhost
> >
> > FROM = "me at abc.com"
> > TO = ["you at nbc.com"]
> >
> > SUBJECT = "Mail from",os.getenv('HOSTNAME')
> SUBJECT = "Mail from "+os.getenv('HOSTNAME')
> >
> > TEXT = "This message is from",os.getenv('HOSTNAME')
> TEXT = "This message is from ",os.getenv('HOSTNAME')
> >
> > message = """\
> > From: %s
> > To: %s
> > Subject: %s
> >
> > %s
> > """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
> >
> > # Send message
> >
> > server = smtplib.STMP(SERVER)
> > server.sendmail(FROM, TO, message)
> > server.quit()
> >
> > =============end script=============
>
>
> --
> David Tomaschik, RHCE, LPIC-1
> System Administrator/Open Source Advocate
> OpenPGP: 0x5DEA789B
> http://systemoverlord.com
> david at systemoverlord.com
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20111118/83925662/attachment.html 


More information about the Ale mailing list