LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash scripting question (https://www.linuxquestions.org/questions/linux-newbie-8/bash-scripting-question-562942/)

johnpaulodonnell 06-19-2007 08:43 AM

bash scripting question
 
Hi.

I'm trying to little bash script to help me automate the conversion of files between two seismic format.

The code that does the conversion exists already and is called codeco3. With my set-up I simply call it from the command line (> codeco3) and interact with it as follows to do the conversion:

codeco3 : enter name of file to be converted
me : name.format_A
codeco3 : enter input file format
me : format_A
codeco3 : enter name for output file
me : name.format_b
codeco3 : enter output file format
me : format.b

But I have a zillion files to be converted and would like to automate the process, and I have not written a script based around an interactive program before...so I'm a bit stuck.

Basically I want the script to read all files in a directory, and pass these all to codeco3 one at a time for conversion - but do not know how to pass them to codeco3 one at a time within a script...

Code:


#!/usr/bin/bash

# script to convert SHM outputted miniseed files
# to SAC format.

list=$(ls)
for file in $list
 do
 
**** codeco3 ??? ****

 done


Centinul 06-19-2007 08:54 AM

I think you are on the right track. I would modify the conversion script to take a command line argument as a parameter instead of prompting the user. That way it will do it without prompting you every single time. The first argument would be called "$1"

Then taking what you have written below and slightly modifying it:

Quote:

Originally Posted by johnpaulodonnell
Code:


#!/usr/bin/bash
 
# script to convert SHM outputted miniseed files
# to SAC format.
 
list=$(ls)
for file in $list
 do
 
./path/to/conversion/codeco3.sh $file
 
 done


I'm not a BASH expert, but hopefully that helps.

Centinul

johnpaulodonnell 06-19-2007 09:03 AM

thanks for that. Yeah, you said what I meant to say. I'd like to do the conversion for all files without any user interaction. The files would be renamed $(file).format_B uniformly. But I still don't see how to do it without prompting the user...

Centinul 06-19-2007 09:05 AM

post your conversion script, we can tweak that as well.

Secondly is their anyway you can programmitically determine which format the files are and which format you want to translate them to? For example is their a relationship like this:

ALL files of format.a convert to format.b and all files of format.c convert to format.d?

johnpaulodonnell 06-19-2007 09:24 AM

All files I want to convert will be in a directory and will all be of same format. What I want to do is to convert these all to a single other format...so it's format_A to format_B all the way.

As for the conversion script, it wasn't me who wrote it...but if I could get around it the way I'm trying to I'd be happier than altering it...it's just that I'd like to know how to automating a process non-interactively via a shell script incorporating the interactive program is done!

http://www.seismo.ethz.ch/products/s...3/codeco3.html

for codeco3 program

Centinul 06-19-2007 10:32 AM

Unless the codec script has some way of taking command line arguments, I don't think you'll find a way around the user interaction problem.

johnpaulodonnell 06-19-2007 10:36 AM

ok.thanks for your help.

chrism01 06-20-2007 07:24 AM

I'm guessing from that web page that it's a compiled FORTRAN prog (although it mentions 2 diff versions ..), so you're looking at a binary.
If this is the case (or you just don't want to mess with it), look at the expect tool eg http://linux.maruhn.com/sec/expect.html . It's specifically designed to handle interactive tools for you.
You'll find a few refs to it here at LQ too.


All times are GMT -5. The time now is 12:35 AM.