From d50cd9c0044c97f800421a6ee2883b9a84b94788 Mon Sep 17 00:00:00 2001 From: Benjamin Collet Date: Sun, 8 Apr 2018 08:51:40 +0200 Subject: [PATCH] zsh functions update --- README.md | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7c9708e..1dcc62d 100644 --- a/README.md +++ b/README.md @@ -20,17 +20,27 @@ On invocation of `ifup`: * if it does and the interface is configured, the script will invoke `ifup` for this interface inside the namespace. -## `zsh` function to start a shell in a namespace +## `zsh` functions to run commands and start a shell in a namespace ``` +nse () { + if [ $# -lt 2 ]; then + echo "Please specify a network namespace and a command" + return + fi + NS=${1} + shift + unshare -m /bin/sh <<-EOF +mount --make-rprivate / +mount --bind /run/network.${NS} /run/network +ip netns exec ${NS} ${@} +EOF +} + nss () { - if [ -z $1 ]; then + if [ $# -ne 1 ]; then echo "Please specify a network namespace" return fi - unshare -m /bin/sh <<-EOF -mount --make-rprivate / -mount --bind /run/network.${1} /run/network -ip netns exec ${1} zsh -i -EOF + nse $1 zsh -i } ```