
Instant message from console in jabber

Most often this problem is solved, for example, by sending a mail message. But it cannot be guaranteed that the message, firstly, will arrive on time, and secondly, that it will be read right away. Then, the administrator will think, we will use IM. But how? To keep, for example, centerim constantly open in screen? Agree, not the most rainbow option.
A
I will give an example of such code.
When I needed such functionality, I went over the existing solutions in such popular languages as C, php, perl, python. Some suggested using pre-built classes, some using module loading. The code was monstrously bulky and unreadable, and I was looking for an elegant solution. And it was found in Python.
So, let's agree that we work in Linux. In fact, the script will probably be able to work on Windows, but I didn’t ask myself such a goal. We will need, in fact, python itself, as well as two modules - any dns and xmpppywhich is introduced in Debian by the python-xmpp package .
The script code is as follows:
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import xmpp,sys
xmpp_jid = 'noreply@some.jabber.server'
xmpp_pwd = 'noreplypass'
to = sys.argv[1]
msg = sys.argv[2]
jid = xmpp.protocol.JID(xmpp_jid)
client = xmpp.Client(jid.getDomain(),debug=[])
client.connect()
client.auth(jid.getNode(),str(xmpp_pwd),resource='xmpppy')
client.send(xmpp.protocol.Message(to,msg))
client.disconnect()
The script, using the JID and password passed to it, is authorized on the server, sends a message and closes the connection. Nowhere is easier. You will need to make a separate account for the script (but you can not, jabber allows multiple simultaneous connections with different resources) and enter the credentials in the variables xmpp_jid and xmpp_pwd .
Save the code to a file, make it executable, run it. The launch is as follows:
/home/username/scripts/send_xmpp_message username@email.server.ru "привет, это твой любимый сервер, не забудь вынуть пиво из серверного шкафа"
The flight of fantasy is unlimited: after a light modification, for example, it will be possible to redirect data to a script instead of passing arguments, and using crontab, send messages according to a schedule.