Statistics
| Branch: | Tag: | Revision:

mininet / util / m @ master

History | View | Annotate | Download (816 Bytes)

1 1bf1a4d5 Bob Lantz
#!/bin/bash
2
3
# Attach to a Mininet host and run a command
4
5
if [ -z $1 ]; then
6
  echo "usage: $0 host cmd [args...]"
7
  exit 1
8
else
9
  host=$1
10
fi
11
12 f66904ab cody burkard
pid=`ps ax | grep "mininet:$host$" | grep bash | grep -v mnexec | awk '{print $1};'`
13 6c22e057 Bob Lantz
14
if echo $pid | grep -q ' '; then
15
  echo "Error: found multiple mininet:$host processes"
16
  exit 2
17
fi
18
19 1bf1a4d5 Bob Lantz
if [ "$pid" == "" ]; then
20
  echo "Could not find Mininet host $host"
21 6c22e057 Bob Lantz
  exit 3
22 1bf1a4d5 Bob Lantz
fi
23
24
if [ -z $2 ]; then
25
  cmd='bash'
26
else
27
  shift
28
  cmd=$*
29
fi
30
31
cgroup=/sys/fs/cgroup/cpu/$host
32
if [ -d "$cgroup" ]; then
33
  cg="-g $host"
34
fi
35
36 5413d2e5 Bob Lantz
# Check whether host should be running in a chroot dir
37
rootdir="/var/run/mn/$host/root"
38 a56e2970 Bob Lantz
if [ -d $rootdir -a -x $rootdir/bin/bash ]; then
39 5413d2e5 Bob Lantz
    cmd="'cd `pwd`; exec $cmd'"
40 a56e2970 Bob Lantz
    cmd="chroot $rootdir /bin/bash -c $cmd"
41 5413d2e5 Bob Lantz
fi
42
43 e16c5fe9 cody burkard
cmd="exec sudo mnexec $cg -a $pid $cmd"
44 5413d2e5 Bob Lantz
eval $cmd