Byobu advanced tricks for linux system administrators

Byobu is a great tool for working on remote servers via a SSH session.

Change default shell

Sometimee it is not easy to change default shell for your login session, for example a AD-backed login session. One trick is to set default shell for byobu sessions:

Add the following lines to ~/.byobu/.tmux.conf:
set -g default-shell /usr/bin/zsh
set -g default-command /usr/bin/zsh

Setup multiple sessions for byoubu on login

Wouldn’t it be nice to have logins, directory and files opened without having to do those things repeatedly every time you login or the server restarts? I have the following bash functions in ~/.bash_aliases to for this purpose.

alias deepops-activate='source /opt/deepops/env/bin/activate'
function bmaas {
sess_name=maas
tmux has-session -t $sess_name 2>/dev/null
if [ $? != 0 ]; then
byobu-tmux new-session -d -s $sess_name -t $sess_name\; \
new-window -n deepops \; \
send-keys 'cd ~/deepops; deepops-activate' C-m \; \
split-window -h \; \
send-keys 'cd ~/deepops;vem config/files/slurm/slurm.conf' C-m \; \
new-window -n dtest \; \
send-keys 'cd ~/deepops-test; deepops-activate' C-m \; \
split-window -h \; \
send-keys 'cd ~/deepops-test; ' C-m \; \ 2>/dev/null
fi
# byobu-tmux switch -t $sess_name;
}

function bservers {
sess_name=servers
tmux has-session -t $sess_name 2>/dev/null
if [ $? != 0 ]; then
byobu-tmux new-session -d -s $sess_name -t $sess_name\; \
new-window -n login \; \
send-keys 'ssh server-login' C-m \; \
split-window -v \; \
split-window -h \;
new-window -n server-metric \; \
send-keys 'ssh server-metric' C-m \; 2>/dev/null
fi
# byobu-tmux switch -t $sess_name;
}

at the end of ~/.bash_aliases I can call these functions:

bmaas

bservers

Then byobu sessions are ready for you to use every time you login. Switching between these sessions can be done with F12 + s shortcut of Byobu.

Leave a Reply

Your email address will not be published.