Category Archives: Tips’n’Tricks

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\\"
    else
        command ssh "$@"
    fi
}

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

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:

PL:23:respawn:/path/to/bin/mydaemon

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

[Unit]
Description=My Respawning Daemon
After=getty.target

[Service]
ExecStart=/path/to/bin/mydaemon
Restart=always

[Install]
WantedBy=multi-user.target

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