tmux is a wonderful tool for displaying virtual consoles on the linux command prompt screen. It’s the next best thing to getting actual GUI windows controllable with a mouse.
Mainly, I use it for ssh purposes. Where I can ssh to a pc that I know has tmux already launched in the background and type.
which attaches the session to the on-going tmux background session, allowing you to see everything that is going on in that process. This is especially useful for embedded systems where there are multiple processes launched in the background and you want to monitor them all.
So I have a tmux script launcher.sh here:
#!/bin/bash SESSION="MPC1" #allow re-launch /usr/bin/tmux has-session -t $SESSION 2> /dev/null && /usr/bin/tmux kill-session -t $SESSION /usr/bin/tmux -2 new-session -d -s $SESSION echo "Launching tmux" /usr/bin/tmux split-window -h /usr/bin/tmux split-window -v /usr/bin/tmux select-pane -t 0 /usr/bin/tmux send-keys -t $SESSION.0 "cd /path/to/binary1folder" C-m /usr/bin/tmux send-keys -t $SESSION.0 "./binary1" C-m /usr/bin/tmux send-keys -t $SESSION.1 "cd /path/to/binary2folder" C-m /usr/bin/tmux send-keys -t $SESSION.1 "./binary2" C-m /usr/bin/tmux send-keys -t $SESSION.2 "cd /path/to/binary3folder" C-m /usr/bin/tmux send-keys -t $SESSION.2 "./binary3" C-m
This basically opens up , three panes and splits the window horizontally first, then splitting again one of the split windows vertically. It then launches a binary in each of the window panes. I won’ t go too much into the scripting here as there are plenty of resources for doing so, like this.
Configuring tmux to boot on startup on CentOS 7
Normally this should be pretty straightforward, but I ran into some hiccups.
sudo nano /etc/rc.local
And edit the rc.local file to include
su -c /path/toyourscript/launcher.sh -l your_user_id
-l your_user_id means that you do the launch of the script launcher.sh as the user your_user_id.
And by right it should launch when CentOS boots, launching launcher.sh in the background which in turn launches tmux. However, I found that one of the abrt startup scripts, abrt-console-notification.sh was interfering with the launching of the tmux process/binaries. It would hang at the console terminal of the tmux screens. Doing the following resolved the problem for me.
cd /etc/profile.d/ chmod -r abrt-console-notification.sh
Basically, make abrt-console-notification.sh non-readable, allowing the profile.d startup process to skip over this particular script. It’s kind of a hack, but it worked. I reckon at most I don’t get the automatic bug reporting tool notifications at the console. Note that this script is run depending on what type of installation you chose when installing CentOS. I think that the minimal installl doesn’t run into this issue.
Hope this it useful to you, let me know!
ps. Here’s a tmux cheat sheet. https://gist.githubusercontent.com/afair/3489752/raw/e7106ac93c8f9602d3843696692a87cfb43c2d21/tmux.cheat