How to read file content and send email on Debian Bullseye

Thomas Passin list1 at tompassin.net
Sat Feb 4 17:59:11 EST 2023


On 2/4/2023 10:05 AM, ^Bart wrote:
> Hi guys,
> 
> 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:
> 
> 2023-01-30 18:30:02 
> /home/my_user/local_folder/upload/my_file_30-01-2023_18-30.txt -> 
> sftp://ftp_user@ftpserver_ip:2201/remote_ftp_folder/my_file_30-01-2023_18-30.txt 0-1660576 4.92 MiB/s
> 
> 2023-02-02 18:30:02 
> /home/my_user/local_folder/upload/my_file_02-02-2023_18-30.txt -> 
> sftp://ftp_user@ftpserver_ip:2201/remote_ftp_folder/my_file_02-02-2023_18-30.txt 0-603093 3.39 MiB/s
> 
> 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 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.

Otherwise you haven't said what part of the process you need help with. 
Reading the log file?  Checking the date?  Triggering the Python script? 
  Sending the email message with Python?

For the latter, it's covered in the Python docs -

https://docs.python.org/3.10/library/email.examples.html




More information about the Python-list mailing list