I have a python script which runs on Ubuntu and processes the content of a MySQL Database. I want to be informed when the script runs into an unhandled exception
or when it is done processing.
What is the appropriate way to make this happen?
I thought of sending myself an email from within python using the method shown in this SO-Answer, but to be able to do that I have to hardcode my logindata - which I am not comfortable with (the script runs on a public server within the company).
Any suggestions to bypass that or to make it happen using a more appropriate way?
To stop code execution in Python you first need to import the sys object. After this you can then call the exit() method to stop the program running. It is the most reliable, cross-platform way of stopping code execution.
Sending Message Once you have registered a channel, you can send a message to it with the send subcommand: notify-run send "Hi from notify-run."
I usually use ps -fA | grep python to see what processes are running. The CMD will show you what python scripts you have running, although it won't give you the directory of the script.
This worked as charm: https://www.quora.com/How-can-I-send-a-push-notification-to-my-Android-phone-with-a-Python-script
ON PC: install notify-me
pip install notify-run
then register it as: notify-run register
now on your mobile scan the code and allow notification from this site.
Then your script can notify you like this:
from notify_run import Notify
notify = Notify()
notify.send('any message you want')
You typically don't need to supply login data when sending an email over SMTP. If I were you, I'd experiment with the code given in the answer you've linked to and try it out with your company's SMTP server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With