/ batch_gen.sh
batch_gen.sh
 1  #!/bin/sh
 2  
 3  #MAX and MIN for topics and num nodes
 4  MIN=5
 5  MAX=100
 6  
 7  #requires bc
 8  getrand(){
 9    orig=$(od -An -N1 -i /dev/urandom)
10    range=`echo "$MIN + ($orig % ($MAX - $MIN + 1))" | bc`
11    RANDOM=$range
12  }
13  
14  getrand1(){
15    orig=$(od -An -N1 -i /dev/urandom)
16    range=`echo "$MIN + ($orig % ($MAX - $MIN + 1))" | bc`
17    return range
18    #getrand1  # call the fun and use the return value
19    #n=$? 
20  }
21  
22  if [ "$#" -ne 2 ] || [ $2 -le 0 ] ; then
23    echo "usage: $0 <output dir> <#json files needed>" >&2
24    exit 1
25  fi
26  
27  path=$1
28  nfiles=$2
29  mkdir -p $path
30  
31  echo "Ok, will generate $nfiles networks & put them  under '$path'."
32   
33  nwtype="newmanwattsstrogatz"
34  nodetype="desktop"
35  
36  
37  for i in $(seq $nfiles)
38  do
39    getrand
40    n=$((RANDOM+1))
41    getrand 
42    t=$((RANDOM+1))
43    getrand 
44    s=`expr $((RANDOM+1)) % $n`
45  
46    dirname="$path/$i/Waku"
47    mkdir "$path/$i"
48    echo "Generating ./generate_network.py --dirname $dirname --num-nodes $n --num-topics $t --nw-type $nwtype --node-type $nodetype --num-partitions 1 --num-subnets $s ...."
49    $(./generate_network.py --dirname $dirname --num-nodes $n --num-topics $t --nw-type $nwtype --node-type $nodetype --num-partitions 1 --num-subnets $s)
50  done