Browse Source

zsh functions update

Benjamin Collet 6 years ago
parent
commit
d50cd9c004
1 changed files with 16 additions and 6 deletions
  1. 16 6
      README.md

+ 16 - 6
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
 ```
-nss () {
-  if [ -z $1 ]; then
-    echo "Please specify a network 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.${1} /run/network
-ip netns exec ${1} zsh -i
+mount --bind /run/network.${NS} /run/network
+ip netns exec ${NS} ${@}
 EOF
 }
+
+nss () {
+  if [ $# -ne 1 ]; then
+    echo "Please specify a network namespace"
+    return
+  fi
+  nse $1 zsh -i
+}
 ```