Skip to content

Commit 337fa1e

Browse files
committed
tutorial/mtu: add duoexec to utility
Add duoexec utility to display side by side two executions.
1 parent f524502 commit 337fa1e

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

tutorials/net/mtu/.bashrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ alias rm='rm -i'
2424

2525
alias _exec='exec'
2626
alias help="/bp/help.sh"
27+
alias duoexec="/bp/duoexec.sh"
2728
alias describe="/bp/describe.sh"
2829

2930
exec(){

tutorials/net/mtu/docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ LABEL org.opencontainers.image.source="https://github.com/bitpuff-io/code/"
1010
LABEL org.opencontainers.image.licenses="BSD"
1111

1212
RUN apt update && apt install -y --no-install-recommends \
13+
byobu \
1314
curl \
1415
iproute2 \
1516
iputils-ping \

tutorials/net/mtu/duoexec.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
source /bp/common.sh
6+
7+
# multi-exec on multiple namespaces
8+
# $1 namespace1
9+
# $2 command1
10+
# $3 namespace2
11+
# $4 command2
12+
# $5 [optional, split: vertical or horizontal ]
13+
14+
if [ $# -lt 4 ] || [ $# -gt 5 ]; then
15+
log_err "Invalid number of parameters"
16+
log_err "Usage: ${0} ns1 cmd1 ns2 cmd2 [horizontal | vertical]"
17+
exit 1
18+
fi
19+
20+
MODE="${5:-horizontal}"
21+
22+
#_check_ns ${1}
23+
NS1=${1}
24+
CMD1=${2}
25+
26+
#_check_ns ${3}
27+
NS2=${3}
28+
CMD2=${4}
29+
30+
# Disable welcome messages for clean view
31+
export BYOBU_NO_WELCOME=1
32+
export BYOBU_DISABLE_STATUS=1
33+
#export BYOBU_BACKEND=tmux
34+
35+
if [ "${MODE}" != "vertical" ]; then
36+
SPLIT_OP="-h"
37+
LAYOUT="even-horizontal"
38+
else
39+
SPLIT_OP="-v"
40+
LAYOUT="even-vertical"
41+
fi
42+
43+
44+
SESSION="duoexec$$"
45+
46+
LABEL1="${CMD1}"
47+
LABEL2="${CMD2}"
48+
CMD1="${SUDO} ip netns exec ${NS1} bash -c \"${CMD1}\""
49+
CMD2="${SUDO} ip netns exec ${NS2} bash -c \"${CMD2}\""
50+
51+
byobu new-session -A -d -s "${SESSION}" "echo ${CMD1}; ${CMD1}"
52+
byobu split-window ${SPLIT_OP} -t "${SESSION}" "echo ${CMD2}; ${CMD2}"
53+
54+
byobu select-layout -t "${SESSION}" ${LAYOUT}
55+
byobu rename-window -t "${SESSION}" "${NS1}$ ${LABEL1} | ${NS2}$ ${LABEL2}"
56+
byobu attach-session -t "${SESSION}"

0 commit comments

Comments
 (0)