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?
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.
[...] 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.
On 2023-02-04 at 17:59:11 -0500,
Thomas Passin <list1@tompassin.net> wrote:
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.
[...]
[...] 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.
xdg-email appears to be for interactive use (it opens the user's
"preferred email composer"); I think sendmail would work much better
from a script.
Otherwise, I had the same initial thought, to add to and/or build a
wrapper around the existing lftp script.
I have never used it, and I did see that wording in the man page, but it
also showed putting all the info on the command line - from, to,
subject, etc - so I thought it might be able to use a command line
client without needed any GUI interaction. But I don't know for sure.
xdg-email appears to be for interactive use (it opens the user's
"preferred email composer"); I think sendmail would work much better
from a script.
Otherwise, I had the same initial thought, to add to and/or build a
wrapper around the existing lftp script.
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
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
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.
For example, try to do whatever parts you know how to do and when some part fails or is missing, ask.
I might have replied to you directly if your email email address did not
look like you want no SPAM, LOL!
The cron stuff is not really relevant and it seems your idea is to read a part or all of a log file, parse the lines in some way and find a line that either matches what you need or fail to find it. Either way you want to send an email out with an appropriate content.
Which part of that do you not know how to do in python? Have you done some reading or looking?
xdg-email appears to be for interactive use (it opens the user's
"preferred email composer"); I think sendmail would work much better
from a script.
Like what I said in another post I think I could use ssmtp than
xdg-email or sendmail...
Otherwise, I had the same initial thought, to add to and/or build a
wrapper around the existing lftp script.
I'd like to know if there's a code made from lftp to understand when an upload file is finished
but certainly I can read it from the log file
and I think it couldn't be hard to find a value in a *.txt file and if
this value is inside of it to send an email like "ok" otherwise a
message with "k.o.".
Regards.
^Bart
For example, try to do whatever parts you know how to do and when some part >> fails or is missing, ask.
You're right but first of all I wrote what I'd like to do and if Python
could be the best choice about it! :)
I might have replied to you directly if your email email address did not
look like you want no SPAM, LOL!
Ahaha! I think you know what is spam and what is a reply\answer to a
post request so you can feel free to use also my email! :)
The cron stuff is not really relevant and it seems your idea is to read a
part or all of a log file, parse the lines in some way and find a line that >> either matches what you need or fail to find it. Either way you want to send >> an email out with an appropriate content.
You got the point!
Which part of that do you not know how to do in python? Have you done some >> reading or looking?
Like what I wrote above I didn't know if Python can does what I need and
if to use Python is a good way I'll start to study how to do it! :)
In my past I used Python for Arduino programming or to do easy things,
what I should do now is little more complex but I understood from years
and years by the Python's powers you can do everything! LOL! :)
Regards.
^Bart
For example, try to do whatever parts you know how to do and when some
part fails or is missing, ask.
I might have replied to you directly if your email email address did
not look like you want no SPAM, LOL!
The cron stuff is not really relevant and it seems your idea is to
read a part or all of a log file, parse the lines in some way and find
a line that either matches what you need or fail to find it. Either
way you want to send an email out with an appropriate content.
Which part of that do you not know how to do in python? Have you done
some reading or looking?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 64:41:20 |
Calls: | 6,712 |
Files: | 12,244 |
Messages: | 5,356,126 |