Change window name while ssh’ing in GNU screen

When using GNU Screen everyday, it can be useful to have some automated title window renaming. I like it when I ssh a remote host. Here is how I do it with a shell function:

ssh() {
    if [[ "$(ps -p $(ps -p $$ -o ppid=) -o comm=)" =~ ^tmux ]]; then
        tmux rename-window "$(echo $* | cut -d . -f 1)"
        command ssh "$@"
        tmux set-window-option automatic-rename "on" 1>/dev/null
    elif [[ "$(ps -p $(ps -p $$ -o ppid=) -o comm=)" =~ ^screen ]]; then
        host=$(echo $* | cut -d . -f 1)
        echo -ne "\ek${host}\e\\"
        command ssh "$@"
        echo -ne "\ekzsh\e\\"
        command ssh "$@"

The trick is to send echo -ne "\ek${host}\e\\". That also works for tmux.

Redis: print to STDOUT from a LUA script

When you want to print to STDOUT from a LUA script executed by “redis-cli –raw –eval”, it doesn’t print to STDOUT but in Syslog. You will need to use “return” instead.

Let’s help yourself with a “logit” function, like this:

local log = {}
local function logit(msg)
  log[#log+1] = msg

-- Some code

    -- Log my string

-- Some more code

-- print log to STDOUT
return log

That’s awesome till you don’t know how to pass arguments to your Redis LUA script ! :-)

Redis: passing args to a LUA script

How did it came in their brain that the arguments where not stored in the ARG[] array but in the KEYS[] one ?

So if you want to call your Redis LUA script this way:

redis-cli --raw --eval myscript.lua arg1 arg2 ...

You have to access your args this way in the LUA script:

local arg1=KEYS[1]
local arg2=KEYS[2]

That’s awesome till you don’t know how to STDOUT print some results :-)

Inittab respawn remplacement for systemd

When upgrading to Debian Jessie and welcoming systemd at your home sweet home, it can be disturbing to not have working inittab respwaning services.

As usual, the inittab config line was looking like this:


So you will need to put in file /etc/systemd/system/mydaemon.service that code example:

Description=My Respawning Daemon



Then to do a “systemctl enable mydaemon.service” for systemd to symlink what it needs.

If you don’t want to reboot for it to work now, use:

systemctl daemon-reload
systemctl start mydaemon.service

Building MongoDB for Debian Jessie

Today Debian Jessie doesn’t have a recent version of MongoDb. They provide 2.4.10 when I (and you if you arrived here) need something newer like 3.0.6. On MongoDB website, you can download Debian packages but only for the already old Wheezy…

So you will need to download the MongoDB 3.0.6 tgz source file here and try to build the .deb on your own. That’s how I did it:

First, I’ve Installed this list of debian packages:

apt-get install debtools devscripts gcc libboost-date-time-dev libboost-dev libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev libgoogle-perftools-dev libpcap-dev libpcre3-dev libreadline-dev libsnappy-dev libstemmer-dev libssl-dev libv8-dev python-pymongo scons dh-systemd

Once you’ve untar the archive, go to the debian/ directory and add thoses links:

ln -s mongodb-org-unstable.control control
ln -s mongodb-org-unstable.rules rules

In the control file change the first line from “Source: mongodb-org-unstable” to “Source: mongodb”.

In the rules files, uncomment each commented scons command, especially in the build-stamp part. I’ve changed it to “scons -j12 all” to build it with 12 parallel gcc process (depends how many cores your CPUs have).

Still in the debian/ directory, In the changelog file add thoses lines at the beginning:

mongodb (3.0.6) unstable; urgency=low

  * Rebuild debian package for Jessie

 -- Aurelien Beaujean <> Thu, 08 Oct 2015 12:02:36 +0200

Then you are ready to build MongoDB by running the command “dpkg-buildpackage -rfakeroot” in the mongodb-src-r3.0.6 directory. It takes a while, for me it took about 15 minutes. And if everything gone good, you shoud get .deb files in the upper directory to give to install to dpkg.

Feel free to comment on this article if you solved some issues I didn’t had while building.

Happy new year from Logstash & syslog

Once you’re running syslog-ng | logstash | elasticsearch for to archive all the syslogs from your servers, there is probably something you didn’t noticed: syslog don’t care about year.

So when 2015 coming, Logstash don’t know about it and push into elasticsearch the year of it’s last starts. So your January 2015 syslogs coming to January 2014 ones…

How I fixed it ? I’ve restarted logstash when I understood the problem, but it was somehow too late.

Some solution is explained here: but you need some more code to handle the year move and using @timestamp don’t allow you to replay piece of logs when you need…

Elasticsearch is in red status ?

Your elasticsearch don’t want to accept connexions or queries anymore after a restart or a “Java heap” memory problem ?

# curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
"cluster_name" : "elasticsearch",
"status" : "red",

You will need to check if one the of indexes is “red” status by requesting the indices list. The command is:

# curl 'localhost:9200/_cat/indices?v'
health status index                pri rep docs.count docs.deleted store.size
red    open   my_index-2014.07.21   3   1   10107061            0      1.7gb          1.7gb
yellow open   my_index-2014.07.22   3   1    6728769            0      1.1gb          1.1gb

What is not said in Elasticsearch documentation is that you will need to delete the datas of the index that is in “red” status to be able to restart elasticsearch. I didn’t find any tool to repair indexes… So datas are losts. You was putting them in the cloud, they gone to space…

That experience made me want to move to another noSQL database… To Be Continued :)

Show transceiver specs on Cisco ASR 9000

The equivalent of a “show inventory” or a “show interfaces transceiver” on a Cisco ASR 9000 is “show controller”:

# show controller tenGigE 0/0/0/0
    Media type: R fiber over 1310nm optics
        Vendor: FxxxxxR
        Part number: FTLXxxxxxxxxL
        Serial number: AxxxxxU
# show controller tenGigE 0/0/0/0 internal
Pluggable Type      : SFP-10G-LR
# show controller tenGigE 0/0/0/1 internal
Pluggable Type      : DWDM-SFP-5494

It shows you the phy details of a specific interface transceiver, while “internal” shows you its type (LR, SR, DWDM, …)

STARTTLS for ClamSMTP server

I didn’t find any patch to enable STARTTLS on client side in ClamSMTP when accepting direct (port 25) connexions, so I wrote it.

You can find my code here on GitHub :

Two options have been added to the clamsmtp.conf file:

TLSKey: /path/to/file.key
TLSCert: /path/to/file.crt

It’s originally from by Stefan Walter. A git repository was actually here but didn’t include the /common/ directory.