LinuxQuestions.org
Help answer threads with 0 replies.
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 06-19-2007, 09:43 AM   #1
johnpaulodonnell
Member
 
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Rep: Reputation: 15
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
 
Old 06-19-2007, 09:54 AM   #2
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
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
 
Old 06-19-2007, 10:03 AM   #3
johnpaulodonnell
Member
 
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Original Poster
Rep: Reputation: 15
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...
 
Old 06-19-2007, 10:05 AM   #4
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
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?
 
Old 06-19-2007, 10:24 AM   #5
johnpaulodonnell
Member
 
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Original Poster
Rep: Reputation: 15
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
 
Old 06-19-2007, 11:32 AM   #6
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
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.
 
Old 06-19-2007, 11:36 AM   #7
johnpaulodonnell
Member
 
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Original Poster
Rep: Reputation: 15
ok.thanks for your help.
 
Old 06-20-2007, 08:24 AM   #8
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,311

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


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting question ajaye1971 Linux - Newbie 1 11-16-2005 08:29 PM
bash scripting question bmfan Linux - Software 6 11-04-2005 09:54 PM
Bash scripting question. pete1234 Programming 23 09-22-2005 07:52 PM
bash scripting question mehesque Programming 2 03-07-2004 02:37 PM
Scripting Question (BASH) merana Linux - General 4 01-12-2003 02:32 PM


All times are GMT -5. The time now is 08:38 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration