{"id":4704,"date":"2017-11-29T23:04:29","date_gmt":"2017-11-29T23:04:29","guid":{"rendered":"https:\/\/islascruz.org\/blog\/?p=4704"},"modified":"2017-11-30T02:17:21","modified_gmt":"2017-11-30T02:17:21","slug":"tmux","status":"publish","type":"post","link":"https:\/\/islascruz.org\/blog\/2017\/11\/29\/tmux\/","title":{"rendered":"tmux"},"content":{"rendered":"<p>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&#8217;m a huge fan of the shell. In linux while I enjoy using GNOME\/XFCE none of them are my favorite desktop (that&#8217;s why I&#8217;m using macOS).<\/p>\n<p>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 <a href=\"https:\/\/islascruz.org\/blog\/2017\/11\/29\/repost-speed-ssh-controlmaster\/\">re-using the current ssh connection<\/a>, which I tend to use since I discovered.<\/p>\n<p>But \u00a0sometimes I need to monitor a server, and then I use several apps, like iftop\/nload, etc&#8230; and it was pain in the ass opening serveral shells to launch every program.<\/p>\n<p>Then I found tmux, which allows you to have several shells in the same shell, I believe using ncurses but it works!.<\/p>\n<p>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&#8217;m able to start whenever I was before closing the connection.<\/p>\n<p>Now, what happens if I have to restart the server?, or what if the computer I&#8217;m monitoring have an issue and shutdown?. Well, I&#8217;ll have to start another tmux session again, do the split and launch the program.<\/p>\n<p>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:<\/p>\n<pre>#!\/bin\/bash<\/pre>\n<pre>tmux new-session -d iftop  -m20m -F192.168.2.0\/24 -i eth1<\/pre>\n<pre>tmux split-window -h nload eth1<\/pre>\n<pre>tmux split-window -v nload enp2s0<\/pre>\n<pre>tmux split-window -v nload eth2<\/pre>\n<pre>tmux split-window -v <\/pre>\n<pre>tmux select-pane 0<\/pre>\n<pre>tmux -2 attach-session -d <\/pre>\n<p>Then, after you login with ssh, just run the script. It will create a set of panes and run a command in every pane. <em>Note that this script is just an example, you have to create your own based on it.<\/em><\/p>\n<hr>\n<p>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&#8217;s the case I would love you to leave a comment with your tips for tmux or better alternatives.<\/p>\n<p>Did this post was useful to you?, share it!<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_4704\" class=\"pvc_stats all  \" data-element-id=\"4704\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/islascruz.org\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;m a huge fan of the shell. In linux while I enjoy using GNOME\/XFCE none of them are my favorite desktop (that&#8217;s why I&#8217;m using macOS). One [&hellip;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_4704\" class=\"pvc_stats all  \" data-element-id=\"4704\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/islascruz.org\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":4715,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[239],"tags":[],"class_list":["post-4704","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips-and-tricks"],"brizy_media":[],"_links":{"self":[{"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/posts\/4704","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/comments?post=4704"}],"version-history":[{"count":5,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/posts\/4704\/revisions"}],"predecessor-version":[{"id":4717,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/posts\/4704\/revisions\/4717"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/media\/4715"}],"wp:attachment":[{"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/media?parent=4704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/categories?post=4704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/tags?post=4704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}