May 19, 2013

How to master your tmux like a BOSS! Generate tmux panes

Here is a killer point! Whatever you do with your tmux call  

$ tmux source-file .tmux.conf   

So I was monitoring several processes on a server from my laptop and whenever I connected to an ssh and lost my connection my tmux would freeze and I had to rebuild the whole structure:

First row:
my main application.
Second row first column: displays its log,
                second column: will display its Errors.
Third row     first column: runs a java profiling tool called jvisualvm on the server and as it doesn't have an X running I forward its X to my laptop, so it needs to be running.
                 second column: is used for copying files to the server.
Finally last row has the iotop and htop for monitoring purposes.

So each time I lose my ssh connection tmux freezes and I have to setup all this and it's a pain it buTT. Now I can have all that in a click of a button:

Steps:
bind a script to a key press like here:
      bind P source-file ~/.tmux/pdev    # this will bind Ctrl+b+P to run the script

and write a baby tmux script to take care of generating that beautiful sketch up there! Like here:


#session1
#new  -s SessionName -n WindowName Command
#neww -n foo/bar foo
#splitw -v -p 50 -t 0 bar 'scala'
#selectw -t 1
#selectp -t 0
selectp -t 0              # Select pane 0
splitw -v -p 80  # Split pane 0 vertically by 50%
selectp -t 1              # Select pane 1
splitw -v -p 80
splitw -v -p 80

splitw -h -p 50      # Split pane 1 horizontally by 25% forhtop and itop
#selectp -t 0              # Select pane 0

selectp -t 1
splitw -h -p 50

selectp -t 3
splitw -h -p 50


respawn-pane -k -t 0 'sshpass -p "PASSWORD" ssh morteza@sm321-01.cise.ufl.edu; tail -f ~/cbpLog.txt'
respawn-pane -k -t 1 'sshpass -p "PASSWORD" ssh morteza@sm321-01.cise.ufl.edu; tail -f ~/cbpLog.txt'
respawn-pane -k -t 2 'sshpass -p "PASSWORD" ssh morteza@sm321-01.cise.ufl.edu; ls'
respawn-pane -k -t 3 'sshpass -p "PASSWORD" ssh -Y morteza@sm321-01.cise.ufl.edu; jvisualvm'
respawn-pane -k -t 4 'sshpass -p "PASSWORD" ssh morteza@sm321-01.cise.ufl.edu; itop'
respawn-pane -k -t 5 'sshpass -p "PASSWORD" ssh morteza@sm321-01.cise.ufl.edu; htop'
selectp -t 0



Thanks to this: http://amjith.blogspot.com/2011/08/scripting-tmux-layouts.html


No comments:

Post a Comment