So, I needed to get some information from a process running, and I thought I'd get those using XMPP.

I often pick python when doing something small and random and "seriously, it's never going into production" kind of plans, so installed a py-xmpppy package and put this together.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys,os,time,xmpp

if len(sys.argv) < 2:
    print "Syntax: xsend text"
    sys.exit(0)

tojid=sys.argv[1]
text=' '.join(sys.argv[1:])
jidparams={}
jidparams['jid']="automabot@example.com/xsendscript"
jidparams['password']="jidspassword"
jid=xmpp.protocol.JID(jidparams['jid'])
cl=xmpp.Client(jid.getDomain(),debug=[])
con=cl.connect()
if not con:
    print 'could not connect!'
    sys.exit()
auth=cl.auth(jid.getNode(),jidparams['password'],resource=jid.getResource())
if not auth:
    print 'could not authenticate!'
    sys.exit()
cl.masterJids=[]
cl.masterJids.append("hereiam@example.org")
for master in cl.masterJids:
    id=cl.send(xmpp.protocol.Message(master,text))
    cl.disconnect()

And that's it, I run it like

$ xmpptell.py "Hi there, just wanted to tell you that there's no internet"

Comments

comments powered by Disqus