From: Urban Wallasch Date: Mon, 22 Apr 2019 17:55:29 +0000 (+0200) Subject: * Implemented 'exec' action to run a command in an existing network namespace context. X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=88248931a32e2abf765f001b4d5cfb77ac9945e1;p=netutil.git * Implemented 'exec' action to run a command in an existing network namespace context. --- diff --git a/nns.sh b/nns.sh index b6e0831..7fa81ad 100755 --- a/nns.sh +++ b/nns.sh @@ -61,9 +61,9 @@ set -x SHORTNAME=${0##*/} usemsg() { - echo "Usage: $1 name action" - echo "where name is the name of a config file or the network" - echo "namespace name and action is one of start | stop | reload." + echo "Usage: $1 name start|stop|restart|exec cmd [arg ...]" + echo " where name is the name of a config file or a network namespace name," + echo " and cmd is a command to execute in the context of an existing namespace." } if [ $# -lt 2 ]; then @@ -216,6 +216,19 @@ stop_nns() { /bin/rmdir $RUNDIR } +# Run a specified command inside a network namespace: +run_nns() { + if ! exist_nns $1 ; then + echo "Network namespace $1 does not exist," + echo "please choose another name" + exit 1 + fi + NNS=$1 + shift + # Run the specified command inside the namespace: + $IP netns exec $NNS su -p -c "$*" $SUDO_USER & +} + case $2 in start) @@ -229,7 +242,9 @@ case $2 in start_nns $NNSNAME ;; run|exec) - echo "TO-DO: implement '$SHORTNAME run ' action." + shift + shift + run_nns $NNSNAME "$@" ;; *) usemsg $SHORTNAME