Shell script for seeds in ns2
HI,I wanna run the same tcl script for ten different seeds using random number ,and then take out the average,how do I do that ?
|
Well, you can start by giving us some details to work with. Don't just assume that we will know what you are talking about.
What is ns2? What exactly is this tcl script? How do you "run it with random seeds", and what kind of output does it give? What exactly is the "average" you want? Where in the output (I assume) are the numbers that need averaging? How exactly do you need them to be totaled and presented? What environment are you using? Standard bash? Some other shell? Finally, what have you tried already, if anything? Have you searched to see if anyone has already done what you want, or something similar that can be adapted to your needs? |
I can't answer the rest, but I can answer a couple of David's questions.
NS2 is the linux network simulator. It's a nice program and capable of simulating an entire network rather than having to buy Cisco Lab equipment or something comperable. TCL is the tool command language. Its used in a few different applications, but NS2 uses it as its network configuration language. I hope this helps flesh out some background for the problem the OP is having. Cheers. Edit: here are links: http://isi.edu/nsnam/ns/ http://en.wikipedia.org/wiki/Tcl Sorry for the wikipedia entry, I couln't find a better explanation. :study: |
[B]HI I posted the question
Quote:
I am using setdest utility in ns2 to generate movement scenarios,it runs like this umair@umair-VirtualBox:~/ns-allinone-2.34/ns-2.34/indep-utils/cmu-scen-gen/setdest$ ls [I] addrmap-example calcdest.o Makefile make-scen-steadystate.csh scene1 scene-30-0-20 setdest setdest.h calcdest emulate Makefile.in README scene-10-0-20 scene-40-0-20 setdest2.cc setdest.o calcdest.cc gentracefiles make-scen.csh rng.o scene-20-0-20 scene-50-0-20 setdest.cc umair@umair-VirtualBox:~/ns-allinone-2.34/ns-2.34/indep-utils/cmu-scen-gen/setdest$ ./setdest usage: <original 1999 CMU version (version 1)> ./setdest -v <1> -n <nodes> -p <pause time> -M <max speed> -t <simulation time> -x <max X> -y <max Y> OR <modified 2003 U.Michigan version (version 2)> ./setdest -v <2> -n <nodes> -s <speed type> -m <min speed> -M <max speed> -t <simulation time> -P <pause type> -p <pause time> -x <max X> -y <max Y> (Refer to the script files make-scen.csh and make-scen-steadystate.csh for detail.) umair@umair-VirtualBox:~/ns-allinone-2.34/ns-2.34/indep-utils/cmu-scen-gen/setdest$ ./setdest -v 1 -n 20 -p 10 -M 32 -t 300 -x 500 -y 674 >scenario now i need to generate this multiple time with different parameters like changing -p pause time like 20,30,49 and so on so I got the shell script from the website Code:
#!/bin/bash I get the following results scenario1' is a directory ./scenario.sh: line 21: ~/ns-allinone-2.34/ns-2.34/indep-utils/cmu-scen-gen/setdest/setdest: No such file or directory ./scenario.sh: line 21: ~/ns-allinone-2.34/ns-2.34/indep-utils/cmu-scen-gen/setdest/setdest: No such file or directory ./scenario.sh: line 21: ~/ns-allinone-2.34/ns-2.34/indep-utils/cmu-scen-gen/setdest/setdest: No such file or directory ./scenario.sh: line 21: ~/ns-allinone-2.34/ns-2.34/indep-utils/cmu-scen-gen/setdest/setdest: No such file or directory ./scenario.sh: line 21: ~/ns-allinone-2.34/ns-2.34/indep-utils/cmu-scen-gen/setdest/setdest: No such file or directory Created the following files -rw-r--r-- 1 umair umair 0 2011-08-13 11:59 scenario1/scen-25-0 -rw-r--r-- 1 umair umair 0 2011-08-13 11:59 scenario1/scen-25-10 -rw-r--r-- 1 umair umair 0 2011-08-13 11:59 scenario1/scen-25-100 -rw-r--r-- 1 umair umair 0 2011-08-13 11:59 scenario1/scen-25-20 -rw-r--r-- 1 umair umair 0 2011-08-13 11:59 scenario1/scen-25-40 and all the created files are empty . |
The script isn't finding the location of your program. You're giving it a bad path.
Tilde (~) expansion doesn't happen inside quoted strings, so your variable ends up containing a literal "~". And tilde expansion happens before parameter expansion, so it remains literal when you use it later as a command. Change this: Code:
setdest_loc="~/ns-allinone-2.34/ns-2.34/indep-utils/cmu-scen-gen/setdest/setdest"; Code:
setdest_loc="$HOME/ns-allinone-2.34/ns-2.34/indep-utils/cmu-scen-gen/setdest/setdest" Other than that, I don't see any major problems with the script. There are a couple of little things I'd do differently, but that's just me. |
@David the H.
thanks for the solution ,your solution worked for me but I found a different way myself and it's working , Code:
#!/bin/bash you tell me which one is better and also Quote:
|
That's certainly cleaner. But this is not right.
Code:
script=cd ~/ns-allinone-2.34/ns-2.34/indep-utils/cmu-scen-gen/setdest/./setdest -v 1 -n 25 -p $i -M 20 -t 100 -x 500 -y 500 > $dest_dir/scen-25-$i In any case, it really isn't much different from the first script. It still works as written. You've just removed the extra variable, which is one of the things I would've considered doing. The modifications I'd make would be minor and mostly cosmetic. The script is mostly just a simple loop after all. You might consider setting up the command as a function, which makes it easier to modify if needed. The options to it can be held in an array inside the function*. I think I would simply cd into the destination directory first and run the command from there, to avoid having to worry about using the full path in the command. Also, [[ is usually better than [, and adding the -p option to mkdir will allow you to modify the script to create further subdirectories, if needed. Finally, you should always define exit codes for a script. That lets you use it in other scripts. Here's my idea: Code:
#!/bin/bash ~~~ *In general variables are for holding strings of data, not code. If you have a sequence of strings, you use an array. While you can hold individual elements of a command inside variables, the command as a whole should be set inside a function: http://mywiki.wooledge.org/BashFAQ/050 |
All times are GMT -5. The time now is 06:42 AM. |