From fd418edd90256acc2af9d7ea5397c112cd7f45d8 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Mon, 14 Mar 2022 00:36:31 +0100 Subject: [PATCH] admin utility --- go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 go diff --git a/go b/go new file mode 100755 index 0000000..9a0ef24 --- /dev/null +++ b/go @@ -0,0 +1,46 @@ +#!/bin/bash + +# list of nodes +nodes() { + ssh nash gnt-node list --no-header -oname | sed 's|\..*||' +} + +# filter the unshare command line into "pid name" +filter_unshare() { + sed -e 's|\([0-9]*\).*chroot \([^ ]*\).*|\1\2|' \ + -e 's|\(.*/\([^/]*\)/[^/ ]*$\)|\2'@$1':\1|' +} + +# enlist all subhosts on all nodes in format: $name@$node:$pid$path +subhosts() { + for NODE in $(nodes) ; do + ssh $NODE pgrep -a unshare | filter_unshare $NODE + done +} + +ALLSUBS="$(subhosts|sort)" +[ -z "$1" ] || SUB="$(echo "$ALLSUBS" | grep -E "^$1@")" + +if [ -z "$SUB" ] ; then + SEL=( $(echo "$ALLSUBS" | sed 's|@.*||') ) + select SUB in ${SEL[*]} ; do + [ -z "$SUB" ] && continue + SUB="$(echo "$ALLSUBS" | grep -E "^$SUB@")" + break + done +fi + +echo "$SUB" + +NAME="${SUB%%@*}" ; SUB="${SUB#*@}" +NODE="${SUB%%:*}" ; SUB="${SUB#*:}" +SPID="${SUB%%/*}" ; SUB="${SUB#*/}" +SPID="$(ssh $NODE ps -hopid --ppid $SPID)" +echo "NODE/SPID = $NODE/$SPID" +LIVE="/$SUB" +CMD="ip netns exec $NAME nsenter -t $SPID -m -p -i -u chroot $LIVE /bin/bash" +CMD="nsenter -t $SPID -m -p -i -u ip netns exec $NAME chroot $LIVE /bin/bash" +[ "$NODE" = "$(hostname -s)" ] || CMD="ssh -t $NODE $CMD" +echo "$CMD" +[ -z "$SPID" ] || exec $CMD +echo "NOT A SUBHOST $LIVE???"