So, for the people that follows my blog or me in twitter/facebok knows that I usually works on Linux/macOS, when using servers I use to use Linux and I’m a huge fan of the shell. In linux while I enjoy using GNOME/XFCE none of them are my favorite desktop (that’s why I’m using macOS).
One of the things I enjoy with the shell is using SSH (Secure Shell), although is pretty simple (launching a remote shell) there is a post in this blog about re-using the current ssh connection, which I tend to use since I discovered.
But sometimes I need to monitor a server, and then I use several apps, like iftop/nload, etc… and it was pain in the ass opening serveral shells to launch every program.
Then I found tmux, which allows you to have several shells in the same shell, I believe using ncurses but it works!.
So, now I was able to launch a tmux session, create my panes (split the windows) then launch the programs I like, and since tmux will remain even if I close the connection I’m able to start whenever I was before closing the connection.
Now, what happens if I have to restart the server?, or what if the computer I’m monitoring have an issue and shutdown?. Well, I’ll have to start another tmux session again, do the split and launch the program.
Could that be easy to do?. Turns out that there is a way to do that, just create a script and launch tmux asking to do the splits and opening the programs in each pane, something like this:
tmux new-session -d iftop -m20m -F192.168.2.0/24 -i eth1
tmux split-window -h nload eth1
tmux split-window -v nload enp2s0
tmux split-window -v nload eth2
tmux split-window -v
tmux select-pane 0
tmux -2 attach-session -d
Then, after you login with ssh, just run the script. It will create a set of panes and run a command in every pane. Note that this script is just an example, you have to create your own based on it.
I know this is not something new, and my sysadmin friends have been using this for a long time, they sure know better options for tmux, you probably will, if that’s the case I would love you to leave a comment with your tips for tmux or better alternatives.
Did this post was useful to you?, share it!
626 total views, 5 views today