LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 09-29-2009, 02:59 PM   #1
Spinoz
LQ Newbie
 
Registered: Sep 2009
Posts: 10

Rep: Reputation: 0
calling director, bash script


Hello to all

I am totally new to linux and appresiate any help.

I have a bash script c2c12_4%.sh which does an iteration over my data set.
I have a main directory called 4%GXG and in that directory I have 3 sub directory (GXG_A, GXG_B, and GXG_C). In GXG_A i have 10 files (similarily with GXG_B & GXG_C), and each file has 4 sub files. The bash script is in each of the 4 directories. If i run the bash script in a terminal it iterates the data in the file and spits the output in the same file. However if I run more than one terminal it takes forever to iterate and many times crashes. I know there is an easy way as writing a loop which calls the directories and iterates the script but that is where I dont know where to start. I checked online but I couldn't find anything concrete or at least close to what I want. Do you have any ideas of how to do this.
S0 basically the following:
4%_GXG-->GXG_A, GXG_B, GXG_C----> in each (cell1 ...cell10)---> in each (A, B, C, D) ---> in each (data and bash script)

Very greatful for any help.

Best
Spinoz,
 
Old 09-29-2009, 04:00 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Hi, welcome to LQ!

Sorry, but to me that description means little. Can you post
an output of
tree 4%GXG

?



Cheers,
Tink
 
Old 09-29-2009, 04:50 PM   #3
Spinoz
LQ Newbie
 
Registered: Sep 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Tinkster View Post
Hi, welcome to LQ!

Sorry, but to me that description means little. Can you post
an output of
tree 4%GXG

?



Cheers,
Tink

Well 4%GXG basically refers to my file directory. I just gave it a name.
So the tree looks like
4%GXG
|
|
________________________|______
| | |
plate1 plate2 plate3
| | |
| | _________|__________________
| | | | | | | | | | | |
| | c1 c2 c3 c4 c5 c6 c7 c8 c9 c10
| _____|______________________
| | | | | | | | | | |
| c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 |
_____________|______________
| | | | | | | | | |
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10

So each plate has 10 directories and within that 10 there are 4 other directories (calling it **). Each directory in ** has the bash script and the data which undergoes iteration from the script analysis.

I would like to combine this such that I tell it to go into file 4%GXG and into plate 1, c1 to c10, then into the ** and finally iterate the data in all files...after it is done it goes to plate 2, repeats everything, then plate 3.

I hope that made sense

Thank you again
 
Old 09-29-2009, 05:56 PM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by Spinoz View Post
Well 4%GXG basically refers to my file directory. I just gave it a name.
So the tree looks like
4%GXG
|
|
________________________|______
| | |
plate1 plate2 plate3
| | |
| | _________|__________________
| | | | | | | | | | | |
| | c1 c2 c3 c4 c5 c6 c7 c8 c9 c10
| _____|______________________
| | | | | | | | | | |
| c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 |
_____________|______________
| | | | | | | | | |
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10

So each plate has 10 directories and within that 10 there are 4 other directories (calling it **). Each directory in ** has the bash script and the data which undergoes iteration from the script analysis.

I would like to combine this such that I tell it to go into file 4%GXG and into plate 1, c1 to c10, then into the ** and finally iterate the data in all files...after it is done it goes to plate 2, repeats everything, then plate 3.

I hope that made sense

Thank you again
Could you say precisely and specifically what you want the script to do? What is its purpose? Follow this recipe:

1. Here is what I hoped would happen ______________________

2. But here is what happened instead ______________________

3. Here is how (2) differs from (1) _______________________

Imagine that your post will be read by someone who doesn't already know what you want. The reason? Your post will in fact be read by someone who doesn't already know what you want.
 
Old 09-29-2009, 06:48 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
A basic soln, assuming the same script is used to process all data and you pull that script out to a top level dir and there are only the dirs/files
you mentioned:
Code:
#!/bin/bash

# move to top dir; ideally supply absolute path eg /home/john/4%GXG
cd 4%GXG

# iterate plate dirs
for pdir in *
do
    cd $pdir

    # iterate cdirs
    for cdir in *
    do
        cd $cdir

        # iterate 4 data dirs; call them ddir
        for ddir in *
        do
            cd $ddir

            # process data files
            <your data processing code goes here>

            cd ..  # back up to prev dir
        done # end data dir 
        cd ..
    done
    cd ..
done
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html

Note that your orig post seems to randomly interchange the words 'file' and 'dir', which is confusing.

HTH

Welcome to LQ

Last edited by chrism01; 09-29-2009 at 06:49 PM.
 
Old 09-30-2009, 08:46 AM   #6
Spinoz
LQ Newbie
 
Registered: Sep 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chrism01 View Post
A basic soln, assuming the same script is used to process all data and you pull that script out to a top level dir and there are only the dirs/files
you mentioned:
Code:
#!/bin/bash

# move to top dir; ideally supply absolute path eg /home/john/4%GXG
cd 4%GXG

# iterate plate dirs
for pdir in *
do
    cd $pdir

    # iterate cdirs
    for cdir in *
    do
        cd $cdir

        # iterate 4 data dirs; call them ddir
        for ddir in *
        do
            cd $ddir

            # process data files
            <your data processing code goes here>

            cd ..  # back up to prev dir
        done # end data dir 
        cd ..
    done
    cd ..
done
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html

Note that your orig post seems to randomly interchange the words 'file' and 'dir', which is confusing.

HTH

Welcome to LQ
Thank you kindly. The processing code is already written and saved as XYZ.sh, do you mean I should include that in the bracket?

My goal is to go into the directories and sub-sub directories and tell it to execute the following XYZ.sh file for all the sub-directories under the main directory 4%GXG.

I apologize if I was unable to be clear, my sincere apologies again.

Thank you in advance
 
Old 09-30-2009, 07:23 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Quote:
do you mean I should include that in the bracket?
No idea what you mean by that.

What I (always) suggest is to create a small test copy eg just 2 dirs at each level, and just 2 data files in each bottom dir and try a test execution.
Maybe start with just listing the filenames instead of processing them and add an

echo "in $dir"

or equiv at each level so you can see what the prog does.
With the links I supplied, you should easily be able to finish it from there.
 
  


Reply



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
A shell script to include a message on line 2 of every text file in a director tree? Rotwang Linux - General 4 02-26-2009 05:01 PM
Calling a bash script from PHP - permission denied helsing Linux - Server 3 08-21-2008 07:30 AM
calling user input in bash script dbmacartney Linux - General 3 05-19-2008 06:55 AM
bash - order of commands when calling remote script? babag Programming 2 04-05-2008 05:10 PM
bash script calling mplayer afrodocter Programming 13 08-23-2005 10:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:47 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
Open Source Consulting | Domain Registration