Masayoshi Kobayashi | 72dc588 | 2013-04-06 06:47:50 +0000 | [diff] [blame^] | 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=`pgrep -f ${host}.banner` |
| 13 | if [ "$pid" == "" ]; then |
| 14 | echo "Could not find Mininet host $host" |
| 15 | exit 2 |
| 16 | fi |
| 17 | |
| 18 | if [ -z $2 ]; then |
| 19 | cmd='bash' |
| 20 | else |
| 21 | shift |
| 22 | cmd=$* |
| 23 | fi |
| 24 | |
| 25 | cgroup=/sys/fs/cgroup/cpu/$host |
| 26 | if [ -d "$cgroup" ]; then |
| 27 | cg="-g $host" |
| 28 | fi |
| 29 | |
| 30 | exec sudo mnexec -a $pid $cg $cmd |