Skip to content

Instantly share code, notes, and snippets.

@basilleaf
Created October 3, 2013 03:18
Show Gist options
  • Save basilleaf/6804317 to your computer and use it in GitHub Desktop.
Save basilleaf/6804317 to your computer and use it in GitHub Desktop.
get SMS notified when a process id no longer exists via python, fabric, gmail
import sys
from time import sleep
import smtplib
import getpass
from fabric.api import env, prompt, local
gmail_pw = getpass.getpass("enter your gmail password: ")
ps_id = prompt("enter process_id: ")
mysql_user = env.user
# you can send SMS using mobile carrier's sms gateway
# http://en.wikipedia.org/wiki/List_of_SMS_gateways
sms_gateway_address = 'YOUR_SMS_GATEWAY_NUMBER'
gmail_address = 'YOUR_GMAIL_ADDRESS'
def watch_ps():
while True:
try:
ps = local('ps %s' % ps_id, capture=True)
print ps
except: # it Fatal Errors but not sure what the real error is..
msg = "Your watched process id %s no longer exists" % ps_id
print msg
sms_msg(msg)
sys.exit()
sleep(5)
def sms_msg(msg):
if gmail_pw:
server = smtplib.SMTP( "smtp.gmail.com", 587)
server.starttls()
server.login(gmail_address, gmail_pw)
server.sendmail(gmail_address, sms_gateway_address, msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment