LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Linux Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/linux-newbie-907609/)

coldjava 10-11-2011 12:37 PM

Linux Newbie
 
Hi everyone, I have very little experience with scripting and linux and i don't how to go about solving this problem.

Create a shell script, driver.sh, that can execute a program with a specific set or parameters an arbitrary number of times. The program name, the parameters and the number of times should be passed to the script. The output from each run should be stored in a reasonable way (so that it is easy to access, analyze and plot it). Please note that you do not need to process the output, only make sure it is stored in a file. The script should take the following parameters: driver.sh [number of times] [program to run] [arguments to the program]

corp769 10-11-2011 12:48 PM

Hello,

Smells like homework to me.... Can you show us what you have so far? We can take it from there and assist, but we will not do your homework for you.

Cheers,

Josh

coldjava 10-11-2011 02:00 PM

Yes, it's part of my assignment and i'm not asking for solution, just trying to understand the problem domain.. I know there will be some sort of loop to run the program an arbitrary number of times but am i suppose to write a program that accepts many parameters and run it multiple times?

This is what i've done so far..

for i in {1..5} // say i want to run it 5 times
do
......
done

chrism01 10-11-2011 08:38 PM

Bookmark these, then try to figure it out using them.
If you get really stuck, show us what you've got and what the problem is/seems to be...

http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

coldjava 10-12-2011 02:44 AM

I know where to find links to books about shell scripting if i wanted. I just needed someone to tell me, this is what i was asked to do, this is how is how to go about it...

rikxik 10-12-2011 04:59 AM

The command line arguments in the shell are stored in $@ variable. That is sufficient to get you started.

coldjava 10-12-2011 06:46 AM

Can't seem to find any tip online on the use of "$@" can you explain more...
This is what ive done so far

#!/bin/bash

for ((i=5; i>0; i--))
do
java Driver 1000 >> output.dat
done

exit 0

run the program 5 times, Driver is the name of the program and i explicitly passed it 1000 as an argument.

fukawi1 10-12-2011 06:51 AM

Do they give you a book to read, or a class to attend, to go along with this assignment?
try googling "bash script parameters", google is your friend...

coldjava 10-12-2011 07:05 AM

This assignment is just to get us familiar with scripting. The course is mainly based on multithreaded programming and it's funny how people here keep telling me to google and stuff. Don't see the point of the forum then.

fukawi1 10-12-2011 07:37 AM

http://lmgtfy.com/?q=bash+script+parameters
First result...

Really, its not that hard...

As for answering what "the point of the forum" is... well.... you know what to do...

rikxik 10-12-2011 08:18 AM

Quote:

Originally Posted by coldjava (Post 4496411)
Can't seem to find any tip online on the use of "$@" can you explain more...
This is what ive done so far

#!/bin/bash

for ((i=5; i>0; i--))
do
java Driver 1000 >> output.dat
done

exit 0

run the program 5 times, Driver is the name of the program and i explicitly passed it 1000 as an argument.

So let us suppose your script is called driver.sh. You are running it with all the arguments etc. Why don't you add a "echo $@" to the second line and see what happens. If you don't know what is the purpose of "$", then I'm afraid you need to do a bit of reading. Unix is all about experimenting and "echo" is your friend for shell script debugging.

coldjava 10-12-2011 10:13 AM

I know what $@ is but can't seem to figure out its use in my script. I think maybe i'm not understanding the question being asked. To my understanding, i'm suppose to provide some arguments say 1000, 2000, 3000 stating them explicitly in the script... and for each arg, the program runs it 5 times and at the same time generating all the argument in the same output.dat file ??

RockDoctor 10-12-2011 03:24 PM

I think this is what you're looking for:

You will write a script, S.
That script will execute a program, P.
Program P needs a bunch of arguments, x1, x2, ... xm.
Program P (with the m parameters) will be executed N times.
Each execution of program P should store its output in a reasonable way.
The last sentence in the original post gives you the name of the script and the sequence in which the other goodies should be given.

Linux_Kidd 10-12-2011 03:42 PM

i'll help with a carrot

[newbie@localhost ~]$ cat test.sh
#!/bin/bash
echo $1 $2 $3

[newbie@localhost ~]$ ./test.sh i am newbie
i am newbie

so there you have your args.

now, use these args in your loop do, etc.

hope that helps some.


All times are GMT -5. The time now is 12:42 PM.