Statistics
| Branch: | Tag: | Revision:

mininet / util / m @ e2eb95a2

History | View | Annotate | Download (566 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 | 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
exec sudo mnexec -a $pid $cg $cmd