{"id":149194,"date":"2020-08-19T03:44:56","date_gmt":"2020-08-18T19:44:56","guid":{"rendered":"http:\/\/4563.org\/?p=149194"},"modified":"2020-08-19T03:44:56","modified_gmt":"2020-08-18T19:44:56","slug":"tmux-%e6%80%8e%e4%b9%88%e7%94%a8-shell-%e8%84%9a%e6%9c%ac%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=149194","title":{"rendered":"tmux \u600e\u4e48\u7528 shell \u811a\u672c\u64cd\u4f5c?"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  tmux \u600e\u4e48\u7528 shell \u811a\u672c\u64cd\u4f5c?               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wsseo <\/span>  <span><i><\/i> 11<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>#!\/bin\/sh #\u670d\u52a1\u5668\u8981\u8d77\u4e00\u4e9b\u7a0b\u5e8f\uff0c\u76ee\u524d\u5728\u6d4b\u8bd5\u9636\u6bb5\uff0c\u6240\u6709\u5f88\u591a\u7ec4\u4ef6\u90fd\u5728\u524d\u53f0\u8fd0\u884c #\u6bcf\u6b21\u90fd\u7528 tmux \u4e00\u4e2a\u4e00\u4e2a\u542f\u52a8\uff0cctrl+b c,ctrl+b c....\uff0c\u6bd4\u8f83\u9ebb\u70e6 tmux new -s testapp \u6267\u884c app01\uff0c\u6709\u524d\u53f0\u8f93\u5165 \u65b0\u5efa\u4e00\u4e2a\u7a97\u53e3\uff0c\u6267\u884c app02 \u518d\u5efa\u4e00\u4e2a\u7a97\u53e3\uff0c\u6267\u884c app03 ... \u6700\u540e\u9000\u51fa \u8fd9\u6837\u7684\u64cd\u4f5c\u7528 shell \u811a\u672c\u600e\u4e48\u5199\uff1f <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>16<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3108214\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             tmux send-keys?<br \/>https:\/\/unix.stackexchange.com\/questions\/409861\/is-it-possible-to-send-input-to-a-tmux-session-without-connecting-to-it                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108215\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : nickchenyx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6070\u597d\u6211\u4e5f\u6709\u8fd9\u6837\u7684\u8bc9\u6c42\uff0c\u6211\u5199\u4e86\u4e2a tmux-init.sh \u811a\u672c\u5b8c\u6210\u8fd9\u4e2a\u5de5\u4f5c\uff0c\u7b49\u4e8e\u91cd\u542f\u7684\u8bdd\u6267\u884c\u4e0b\u811a\u672c\u5c31\u53ef\u4ee5\u62c9\u8d77\u5de5\u4f5c\u53f0\u4e86\u3002<\/p>\n<p>&#8220;`shell<br \/># new bastion session<br \/>tmux new -s bastion -d<br \/># rename window<br \/>## &#8212; DEV &#8212;<br \/>tmux rename-window -t &#8220;bastion:1&#8221; dev<br \/># send command<br \/>tmux send -t &#8220;bastion:dev&#8221; &#8216;\/Users\/nickchen\/workspace\/bastion.sh java-run &#8220;cd \/home\/nickchen\/java-app\/&#8221;&#8216; Enter<br \/># split window horizontally<br \/>tmux split-window -t &#8220;bastion:dev&#8221;<br \/>tmux send -t &#8220;bastion:dev&#8221; &#8216;\/Users\/nickchen\/workspace\/bastion.sh inner-01 &#8220;cd \/opt&#8221;&#8216; Enter<br \/># split window vertically<br \/>tmux split-window -h -t &#8220;bastion:dev&#8221;<br \/>tmux send -t &#8220;bastion:dev&#8221; &#8216;\/Users\/nickchen\/workspace\/bastion.sh inner-02 &#8220;cd \/opt&#8221;&#8216; Enter<br \/>&#8220;`<\/p>\n<p>\u8fd9\u662f\u4e00\u90e8\u5206\u5566\uff0c\u672c\u8d28\u4e0a\u90fd\u662f\u4e00\u6837\u7684\u539f\u7406\uff0c\u53bb\u770b\u4e0b tmux send \u7684\u64cd\u4f5c\u5c31\u884c\uff0c\u6211\u8fd9\u91cc\u662f\u521b\u5efa\u591a\u4e2a window + \u6bcf\u4e2a window \u5206\u591a\u4e2a panel \u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108216\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lululau <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             systemd, supervisor, foreman \u4e4b\u7c7b\u7684\u4e0d\u9999\u5417<\/p>\n<p>\u975e\u7528 tmux \u7684\u8bdd\uff0c\u76f4\u63a5\u8c03 tmux sub-commands \u4e5f\u53ef\u4ee5\uff0c\u6216\u8005\u7528 tmuxinator \u4e4b\u7c7b\u7684                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108217\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : vsyour <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &#8220;`bash<br \/>cd ;for i in `ls results_*\/ -d`;do cd;cd $i;tmux new -s $i -d;tmux send -t &#8220;$i&#8221; &#8216;for i in `seq 3`;do python3 run.py ;sleep 600;done&#8217; Enter;done<\/p>\n<p>&#8220;`<br \/>\u53c2\u8003<br \/>\u529f\u80fd\u4ecb\u53ec:<br \/>1. \u626b\u63cf\u5f53\u524d\u76ee\u5f55\u4e2d results_ \u5f00\u5934\u7684\u76ee\u5f55<br \/>2. \u8fdb\u5165\u5f53\u524d\u7528\u6237,\u8fdb\u5165 results_ \u5217\u8868\u4e2d\u7684\u4e00\u4e2a\u76ee\u5f55.<br \/>3. \u521b\u5efa\u4e00\u4e2a\u4ee5 results_xxxx \u547d\u540d\u7684 tmux \u653e\u5230\u540e\u53f0<br \/>4. \u6267\u884c results_xxxx \u76ee\u5f55\u4e0b\u7684 run.py \u811a\u672c. \u6267\u884c 3 \u6b21.\u6bcf\u6b21\u6267\u884c\u5b8c\u540e\u6682\u505c 10 \u5206\u949f.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108218\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chenqh <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             tmuxp?                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108219\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chenqh <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd8\u6709\u8f93\u5165\uff1f\u90a3\u5ffd\u7565\u6211\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108220\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wsseo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @chenqh \u662f\u6709\u8f93\u51fa\uff0c\u7b14\u8bef\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108221\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ksc010 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/github.com\/tmux-python\/libtmux <br \/>python \u64cd\u4f5c tmux \u7684\u5e93                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108222\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chenqh <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wsseo \u90a3\u5c31 tmuxp                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108223\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chenqh <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             tmux \u5173\u95ed\u81ea\u52a8 rename<\/p>\n<p>vim ~\/.tmux.conf<\/p>\n<p>\u6dfb\u52a0<br \/>&#8220;`<\/p>\n<p>set-window-option -g automatic-rename off<br \/>set-option -g allow-rename off<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108224\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wsseo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5148\u7528\u7b28\u65b9\u6cd5<br \/>&#8220;`<br \/>#!\/bin\/sh<br \/>#\u670d\u52a1\u5668\u8981\u8d77\u4e00\u4e9b\u7a0b\u5e8f\uff0c\u76ee\u524d\u5728\u6d4b\u8bd5\u9636\u6bb5\uff0c\u6240\u6709\u5f88\u591a\u7ec4\u4ef6\u90fd\u5728\u524d\u53f0\u8fd0\u884c<br \/>#\u6bcf\u6b21\u90fd\u7528 tmux \u4e00\u4e2a\u4e00\u4e2a\u542f\u52a8\uff0cctrl+b c,ctrl+b c&#8230;.\uff0c\u6bd4\u8f83\u9ebb\u70e6<br \/>tmux new -s testapp -d<br \/>tmux send-keys -t testapp:0 &#8216;ping www.baidu.com&#8217; C-m<br \/>tmux new-window -t testapp:1<br \/>tmux send-keys -t testapp:1 &#8216;vi haha.txt&#8217; C-m<br \/> &#8230;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108225\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wsseo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             tmux new-window -t testapp:1 -d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108226\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : LudwigWS <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u633a\u6709\u610f\u601d\u7684\uff0c\u5b66\u4e60\u4e00\u4e0b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108227\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ksc010 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd8\u6709\u4e00\u4e2a\u65b9\u6cd5\u5c31 \u5b89\u88c5 mux<br \/>\u4f7f\u7528\u7f16\u5199\u914d\u7f6e\u6587\u4ef6                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108228\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : secondwtq <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u6b63\u597d\u641e\u8fc7\u8fd9\u4e2a\uff0c\u9700\u6c42\u662f\u7ed9 B \u7ad9\u76f4\u64ad up \u4e3b\u5f55\u56de\u653e\u3002\u65b9\u6848\u662f\u5728\u4e00\u4e2a tmux pane \u91cc\u9762\u8d77\u4e00\u4e2a\u5faa\u73af\u8f6e\u8be2 B \u7ad9 API\uff0c\u68c0\u6d4b\u5230\u72b6\u6001\u5728\u76f4\u64ad\u5c31\u518d\u5f00\u4e00\u4e2a pane \u7528 you-get \u4e0b\u8f7d\uff0c\u5b8c\u540e ffmpeg \u8f6c\u4e00\u904d\uff1a https:\/\/github.com\/secondwtq\/bmon<\/p>\n<p>\u7528\u4e0d\u7740 send-keys\uff0c\u76f4\u63a5\u4e1c\u897f\u5199\u8fdb\u4e00\u811a\u672c\u91cc\u9762 split-pane\/new-window\/split-window \u5c31\u884c\uff0c\u4e0d\u7136\u4f60\u5f00\u7684 shell \u8fd8\u5f97\u624b\u52a8\u5173                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108229\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : billgreen1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             tmuxinator                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>tmux \u600e\u4e48\u7528 shell \u811a\u672c&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/149194"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=149194"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/149194\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=149194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=149194"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=149194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}