How to read file content and send email on Debian Bullseye

Peter J. Holzer hjp-python at hjp.at
Sun Feb 5 09:13:49 EST 2023


On 2023-02-04 17:59:11 -0500, Thomas Passin wrote:
> On 2/4/2023 10:05 AM, ^Bart wrote:
> > On a Debian Bullseye server I have a lftp upload and after it I should
> > send an email.
> > 
> > I thought to read the lftp log file where I have these lines:
[...]
> > I'd like to use Python to check, from monday to friday (the lftp script
> > runs in crontab from monday to friday) when the upload works is finished
> > and I should send an email.
> > 
> > I could read by Python lftp.log and after it if there's a line with the
> > same day of the machine I could send an email with ok otherwise the
> > email will send a message with "no upload".
> > 
> > How could I do by Python?
> 
> Not Python, but you could run a shell script

If you can run a shell script you can also run a python script.
Linux/Unix is almost completely agnostic about interpreters. You
generally just invoke "the program" and then the kernel examines the
first few bytes to determine what to do with it.

> that sends the file with lftp, and depending on the return code uses
> xdg-email to send one of the two messages. This would probably be
> simpler than using Python.

Probably. But Python gives you more control. Tradeoffs, tradeoffs ...

For something like this I'd say go with what you're most familiar with
and what takes the least effort to get the job done.
For a simple one line notification I'd write a shell script invoking
/usr/sbin/sendmail. If I wanted it to be a bit fancier (e.g. a table
with the uploads over the last few days) I'd probably write a Python
script to get the MIME/HTML structure right (and still use sendmail to
actually send the mail).

xdg-mail can be anything or not be configured at all - so it might not
be the best choice.

> Otherwise you haven't said what part of the process you need help with.

Yeah, that was the reason I didn't reply to the original mail. I simply
couldn't figure out where the problem was.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20230205/10adc539/attachment.sig>


More information about the Python-list mailing list