best way to automate shell commands - shell script or python scripts or something els
Hi,
I want to automate a few shell commands. I want to compile my program for different options and run it. These options are stored in a file. So, I am supposed to read all the options from the file. Compile a particular program with one option at a time. Run that program. Then compile again with another option from the file. Do this till all the options in the file are exhausted. I am not sure, what is the best way to automate this. Should I write shell scripts or should I try python script or something else. Thanks Parang |
Like being a good mechanic, being a good system admin requires using the right tool for the job.
This is something that can be done with BASH and in all honesty it's hard to give a good recommendation without knowing how in depth the program being run is, how many options and what they are, etc.. Personally, this sounds like something I would use python for as it's by design an interpretive language that is usually really good at handling input like this easily. But if it's a small set of options and a quick task something a simply as a one-line for loop could get the job done. If you can give some more detail we can probably give you better answers, I hope some of this info helps. |
Thanks Kustom42.
Here is what I want to do: gcc uses several compile time options like -fdce or -fdse etc. There are 60 such optimization flags documented. I have copy pasted all these documented flags in a file. Now I want to use one flag at a time to compile a program. Then run that program 5 times. After that take another flag from the file and repeat this process until all flags are exhausted. Now, someone suggested me to use python for this and someone said shell script. I am confused. I dont know both shell scripting and python. I want to learn the one that is best suited for this type of automation. Thanks |
If I were you I would use bash.
Read in one line each of the flag files => compile => exec 5 times and repeat. Example: while read flag; do gcc $flag somefile.c for i in 1 2 3 4 5 do ./a.out done done < gccflags.txt |
My only concern is how to read flag options from the file and put it in a list or something. And then iterate through that list.
|
I see, I missed that part.
What does that file look like? It all depends, for example if it is like so: someflag - description of someflag someotherflag - description of someother flag then you can us: cut -f1 -d '-' to delimit by '-' and get the first field which is the flag name. |
Quote:
Code:
for line in $(cat ./compileoptions.txt) |
Its a simple file like this:
-fdse -fdce . . . Now how to put these options in a list to iterate over? |
Quote:
Build your fundamentals, learn BASH. Then learn another language. Scripting languages are kind of like different types of vehicles, each one gets you from a to b but they all do it slightly different and everybody has their favorite. If you want to learn python read this, its a great tutorial: learnpythonthehardway.org/ ---------- Post added 08-08-12 at 01:13 PM ---------- Quote:
|
Thanks Kenneth and Kustom42.
@Kustom42: Sure. Will try to learn BASH first followed by python. :) |
Quote:
Even if you already know some of the basics this book will fill in alot of the holes and get you into some really cool bash scripting exercises toward the end. |
|
All times are GMT -5. The time now is 06:18 PM. |