Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to notify myself when a python script runs into an error or just stops?

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?

like image 751
Aufwind Avatar asked Sep 08 '11 16:09

Aufwind


People also ask

How do you stop a Python script gracefully?

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.

How do I notify run?

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."

How do I know if a Python script is running?

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.


2 Answers

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')
like image 182
user1953366 Avatar answered Sep 28 '22 02:09

user1953366


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.

like image 45
NPE Avatar answered Sep 28 '22 00:09

NPE