News for hackers. Stuff that matters.
Re:Understanding Awk by m463 on Thursday September 30, 2021 @03:51PM (#28710526)
IMHO, that's too big for awk, why not python?

for example:

    #!/usr/bin/python
    import smtplib
    from email.mime.text import MIMEText

    msg = 'hi'
    subj='read this!'

    smtp_server='mail.example.com'
    smtp_from='[email protected]'
    smtp_to='[email protected]'

    m = MIMEText(msg)

    m['To'] = smtp_to
    m['From'] = smtp_from
    m['Subject'] = subj

    s = smtplib.SMTP(smtp_server)
    s.sendmail(smtp_from, [smtp_to], m.as_string())
    s.quit()

of course, you seem to think in gawk so if that works for you that's what you should continue doing!

by the way, I hacked this example from another script which attached a logfile:

    with open(arg.logfile) as f:
        log_contents = f.read()

    m = MIMEText(log_contents)
you can also use:

    from email.mime.image import MIMEImage
    from email.mime.text import MIMEText
    from email.mime.multipart import MIMEMultipart
and then:

    m = MIMEMultipart()
    m.attach(MIMEText('\n\n%s\n\n'%xkcd_img_title))
    m.attach(MIMEImage(xkcd_img))
Re:Understanding Awk by chousuke on Thursday September 30, 2021 @04:20PM (#28710859)
Your script doesn't even do the same thing. You are importing a library that implements SMTP, which is missing the point.

The AWK script doesn't need libraries, so it can actually be useful in places where you have awk but not Python.