Statistics
| Branch: | Tag: | Revision:

mininet / util / m @ master

History | View | Annotate | Download (816 Bytes)

1
#!/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
pid=`ps ax | grep "mininet:$host$" | grep bash | grep -v mnexec | awk '{print $1};'`
13

    
14
if echo $pid | grep -q ' '; then
15
  echo "Error: found multiple mininet:$host processes"
16
  exit 2
17
fi
18

    
19
if [ "$pid" == "" ]; then
20
  echo "Could not find Mininet host $host"
21
  exit 3
22
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
# Check whether host should be running in a chroot dir
37
rootdir="/var/run/mn/$host/root"
38
if [ -d $rootdir -a -x $rootdir/bin/bash ]; then
39
    cmd="'cd `pwd`; exec $cmd'"
40
    cmd="chroot $rootdir /bin/bash -c $cmd"
41
fi
42

    
43
cmd="exec sudo mnexec $cg -a $pid $cmd"
44
eval $cmd