
Using mcabber via ssh on a remote server with notifications
In this article, I will tell you how to keep the mcabber jabber client running on a remote server constantly and use it when connecting to the server via ssh. It will also describe how you can implement notifications of incoming messages.
Profits from such a scheme are as follows:
The disadvantages include:
Running and using mcabber on a remote server is easy. In principle, there is almost no difference compared to the setting locally.
For experiments, you can use the blinkenshell.org service , which provides free shell accounts for sitting on their irc channel. However, to become a full user there you need to spend a couple of days, and their server response is not the best. The article is written on an example setup for blinkenshell server, but you can easily apply it for your own.
To run mcabber on the server, you can use the following command:
(tmux is an analog of screen, in my subjective opinion it is better)
On the local computer, then it will be enough to execute in the terminal:
where -d means that any other tmux mcabber session should be detached first. Thus, it is achieved that mcabber will be connected from only one computer. blinkenshell - an alias configured in ~ / .ssh / config.
If you followed this guide, you can write in the awesome config:
and thereby reduce the launch of the jabber client on the computer to the Win + `key combination, after which a terminal will open with an ssh session in which mcabber will already be launched.
It becomes more interesting when we want event notifications on the remote mcabber.
In mcabberrc on the server, write the following lines: The
contents of ~ / .mcabber / event.sh are small: By doing this we create a logfile on the server to which all mcabber events will be added.
For notifications, I used a python script written by mcabber. The kit comes with a completely understandable configuration file and readme. The script and configuration file should be placed in the ~ / .mcabber / directory on the local computer.
Then there we create a remote_events.sh script with the following contents: It connects via ssh to a remote server and reads the contents of ~ / .mcabber / logfile. When launched, the script will only respond to the last mcabber event (-n0 switch). And then it will constantly monitor changes in this file (-F switch) and send new events to the notification script.
That's all. Now you can load your computer by simply starting remote_events.sh, connecting via ssh to the server where mcabber is waiting for you and working with it as if it were running locally.
PS I am pleased to hear suggestions for optimizing this scheme.
Profits from such a scheme are as follows:
- you are constantly on-line
- if the connection suddenly breaks, you do not have to log in and lose (in an unsuccessful scenario) offline messages
- logs are stored in one place and are accessible from everywhere where there is internet
- you can use mcabber from any device that supports ssh, be it mobile or web client
- They say that ssh eats less traffic than xmpp (did not check)
The disadvantages include:
- server need
- interface slowdown (on slow channels)
- the need to use a console client (for some it’s even a plus)
Running and using mcabber on a remote server is easy. In principle, there is almost no difference compared to the setting locally.
For experiments, you can use the blinkenshell.org service , which provides free shell accounts for sitting on their irc channel. However, to become a full user there you need to spend a couple of days, and their server response is not the best. The article is written on an example setup for blinkenshell server, but you can easily apply it for your own.
To run mcabber on the server, you can use the following command:
tmux new-session -d -s mcabber mcabber
(tmux is an analog of screen, in my subjective opinion it is better)
On the local computer, then it will be enough to execute in the terminal:
ssh -t blinkenshell 'LANG=ru_RU.UTF-8 tmux attach -d -t mcabber'
where -d means that any other tmux mcabber session should be detached first. Thus, it is achieved that mcabber will be connected from only one computer. blinkenshell - an alias configured in ~ / .ssh / config.
If you followed this guide, you can write in the awesome config:
awful.key({ modkey }, "grave", function () scratch.drop("urxvtc -e ssh -t blinkenshell 'LANG=ru_RU.UTF-8 tmux attach -d -t mcabber'", bottom, center, 0.98, 0.95) end),
and thereby reduce the launch of the jabber client on the computer to the Win + `key combination, after which a terminal will open with an ssh session in which mcabber will already be launched.
It becomes more interesting when we want event notifications on the remote mcabber.
In mcabberrc on the server, write the following lines: The
set events_command = ~/.mcabber/event.sh
contents of ~ / .mcabber / event.sh are small: By doing this we create a logfile on the server to which all mcabber events will be added.
#!/bin/sh
echo $@ >> logfile
For notifications, I used a python script written by mcabber. The kit comes with a completely understandable configuration file and readme. The script and configuration file should be placed in the ~ / .mcabber / directory on the local computer.
Then there we create a remote_events.sh script with the following contents: It connects via ssh to a remote server and reads the contents of ~ / .mcabber / logfile. When launched, the script will only respond to the last mcabber event (-n0 switch). And then it will constantly monitor changes in this file (-F switch) and send new events to the notification script.
#!/bin/zsh
SERVER=blinkenshell
EVSCRIPT=~/.mcabber/mcevent.py
CONFFILE=~/.mcabber/mcevent.cfg
ssh $SERVER 'tail -n0 -F ~/.mcabber/logfile' < /dev/null | $EVSCRIPT -c $CONFFILE &|
That's all. Now you can load your computer by simply starting remote_events.sh, connecting via ssh to the server where mcabber is waiting for you and working with it as if it were running locally.
PS I am pleased to hear suggestions for optimizing this scheme.