LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-11-2011, 01:37 PM   #1
coldjava
LQ Newbie
 
Registered: Oct 2011
Posts: 9

Rep: Reputation: Disabled
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]

Last edited by coldjava; 10-11-2011 at 01:44 PM.
 
Old 10-11-2011, 01:48 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
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
 
Old 10-11-2011, 03:00 PM   #3
coldjava
LQ Newbie
 
Registered: Oct 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
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
 
Old 10-11-2011, 09:38 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,258

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
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/
 
1 members found this post helpful.
Old 10-12-2011, 03:44 AM   #5
coldjava
LQ Newbie
 
Registered: Oct 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
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...
 
Old 10-12-2011, 05:59 AM   #6
rikxik
Member
 
Registered: Dec 2007
Posts: 88

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

Last edited by rikxik; 10-12-2011 at 06:00 AM. Reason: Grammer
 
Old 10-12-2011, 07:46 AM   #7
coldjava
LQ Newbie
 
Registered: Oct 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
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.
 
Old 10-12-2011, 07:51 AM   #8
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 190Reputation: 190
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...
 
Old 10-12-2011, 08:05 AM   #9
coldjava
LQ Newbie
 
Registered: Oct 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
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.
 
Old 10-12-2011, 08:37 AM   #10
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 190Reputation: 190
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...
 
0 members found this post helpful.
Old 10-12-2011, 09:18 AM   #11
rikxik
Member
 
Registered: Dec 2007
Posts: 88

Rep: Reputation: 19
Quote:
Originally Posted by coldjava View Post
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.
 
Old 10-12-2011, 11:13 AM   #12
coldjava
LQ Newbie
 
Registered: Oct 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
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 ??
 
Old 10-12-2011, 04:24 PM   #13
RockDoctor
Senior Member
 
Registered: Nov 2003
Location: Minnesota, US
Distribution: Fedora, Linux Mint, Ubuntu
Posts: 1,514

Rep: Reputation: 326Reputation: 326Reputation: 326Reputation: 326
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.
 
Old 10-12-2011, 04:42 PM   #14
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 540

Rep: Reputation: 60
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.

Last edited by Linux_Kidd; 10-12-2011 at 04:45 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off




All times are GMT -5. The time now is 01:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration