I've wrote a little script to launch a program and send a mail if a program has quit:
#!/usr/bin/env python
# coding: utf8
import psutil
from email.mime.text import MIMEText
from subprocess import Popen, PIPE
import time
import os
program = "transmission-gtk"
if not program in [psutil.Process(i).name for i in psutil.get_pid_list()]:
try:
os.system(program)
text = "but it has been restarted"
except IOError as e:
text = "The restart failed!\n" + e
time.sleep(2)
msg = MIMEText("Transmission has been closed !!\n" + text)
msg["From"] = "[email protected]"
msg["To"] = "[email protected]"
msg["Subject"] = "subject"
p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE)
p.communicate(msg.as_string())
The script is launched by cron, every 15 min. All works, except one thing: transmission quit at the same moment the script quits...
I don't want to write a permanent script (raspberry-pi), so a while loop is not what I want.
Then, how to launch my program ?