1 script or multiple scripts?? - check files, run jobs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 1 script or multiple scripts?? - check files, run jobs
# 1  
Old 11-04-2008
1 script or multiple scripts?? - check files, run jobs

Question for anyone that might be able to help:

My objective is to eheck if a file (a source file) exists in a directory. If it does then, I'd like to call an application (Informatica ETL file...not necessary to know) to run a program which extracts data and loads it into multiple targets.

There are mutliple sources files to check for, and multiple applications to call, but the structure of the script should be the same for each source/target pair.

Hence would it be better to use 1 script which checks for all the files and runs a specific app depending on whether a specific file exists, or run a simply create 1 script template, and multiple scripts, 1 for each source/target pair?

The question also relates to job scheduling, schedule 1 script (which would be more advanced of a script considering all the looping or such), or schedule mutliple simpler scripts?

Any help is appreciated - novice script writer.
# 2  
Old 11-04-2008
Hammer & Screwdriver My suggestion

one script that executes all commands
one text file with all the parameters and instructions

Then, your script would execute a loop reading all the entries in your text file with all necessary parameters.

At least, that is how I woudl approach your question.
# 3  
Old 11-04-2008
one way:

Write a simple driver script, then use a data file to supply program name(s), data file -
use "progname -p parm1" for programs that require options.

mycontrolfile:
Code:
datafile1 script.sh "someprogram1 -p parm1 -q parm2"
datafile2 script1.sh someprogram3 anotherprogram script3.sh

script
Code:
#!/bin/ksh
while read datafile prog1 prog2 prog3  prog4  prog5
do
    if [[ ! -s $datafile ]] ; then  # no data file, skip over it?
        continue
    fi
    # run up to 5 programs against the datafile
    for prog in $prog1 $prog2 $prog3 $prog4 $prog5
    do
          "$prog" "$datafile"
    done 
done < mycontrolfile

For example, $prog3 (on first line in the input file) will evaluate to "" if it is empty. So the for loop terminates early. On the second line of datafile $prog5 is "".
# 4  
Old 11-04-2008
Quote:
Originally Posted by joeyg
one script that executes all commands
one text file with all the parameters and instructions

Then, your script would execute a loop reading all the entries in your text file with all necessary parameters.

At least, that is how I would approach your question.
This sounds like a feasible approach, although at this point I'm not quite sure on how to reference a text file which is read through a loop in main script. But it sounds straightforward enough that when I do create the script I should be able to find tons of information calling text files (seems simple enough). Thanks for the info and suggestion, I've only written scripts sparecly in my time Smilie
# 5  
Old 11-04-2008
Quote:
Originally Posted by jim mcnamara
one way:

Write a simple driver script, then use a data file to supply program name(s), data file -
use "progname -p parm1" for programs that require options.

mycontrolfile:
Code:
datafile1 script.sh "someprogram1 -p parm1 -q parm2"
datafile2 script1.sh someprogram3 anotherprogram script3.sh

script
Code:
#!/bin/ksh
while read datafile prog1 prog2 prog3  prog4  prog5
do
    if [[ ! -s $datafile ]] ; then  # no data file, skip over it?
        continue
    fi
    # run up to 5 programs against the datafile
    for prog in $prog1 $prog2 $prog3 $prog4 $prog5
    do
          "$prog" "$datafile"
    done 
done < mycontrolfile

For example, $prog3 (on first line in the input file) will evaluate to "" if it is empty. So the for loop terminates early. On the second line of datafile $prog5 is "".
Thanks for the Info and I appreciate the level of detail! Looks like a great approach that I'll have to further understand and utilize when I create the scripts (I'm in design phase right now). Curious, when you say 'read data file' in the script, is that synonomous with 'read mycontrolfile'? Or are those two different things? In addition, if you state 'prog1 prog 2' etc in the script file, how does the reference to 'someprogram1', 'anotherprogram' come into play?
# 6  
Old 11-04-2008
Hammer & Screwdriver start with somehting simpler

Here is a file I want to process
Code:
> cat file30
55 65 48 45 48 68 32 68 44 34 88 65
82 63 52 54 51 68 75 0 0 20 10 77
55 77 60 55 22 60 40 25 75 55 45 90
20 80 33 63 0 64 32 22 75 0 43 56
54 54 12 35 48 87 65 12 77 85 0 15

For each instance, there are 12 parameters.
Now my script:
Code:
while read x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12
  do echo "start process"
  echo "x2 = "$x2
  echo "x9 = "$x9
done <file30

And its execution:
Code:
start process
x2 = 65
x9 = 44
start process
x2 = 63
x9 = 0
start process
x2 = 77
x9 = 75
start process
x2 = 80
x9 = 75
start process
x2 = 54
x9 = 77

My example only uses two of the variables I am reading in, but you should get the idea. I have a text file with paramaters, and then read through the file executing commands on my read variables.
# 7  
Old 11-05-2008
Quote:
Originally Posted by joeyg
Here is a file I want to process
Code:
> cat file30
55 65 48 45 48 68 32 68 44 34 88 65
82 63 52 54 51 68 75 0 0 20 10 77
55 77 60 55 22 60 40 25 75 55 45 90
20 80 33 63 0 64 32 22 75 0 43 56
54 54 12 35 48 87 65 12 77 85 0 15

For each instance, there are 12 parameters.
Now my script:
Code:
while read x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12
  do echo "start process"
  echo "x2 = "$x2
  echo "x9 = "$x9
done <file30

And its execution:
Code:
start process
x2 = 65
x9 = 44
start process
x2 = 63
x9 = 0
start process
x2 = 77
x9 = 75
start process
x2 = 80
x9 = 75
start process
x2 = 54
x9 = 77

My example only uses two of the variables I am reading in, but you should get the idea. I have a text file with paramaters, and then read through the file executing commands on my read variables.
I think I see what you're saying here. But i didn't clarify that I won't be using unix to read the file. All I'm doing is using shell script to see if the file exists on a directory. If it does, the I'll call an external program to execute (extract and load data from) the file.

As such, I'm looking to see how I should handle multiple (source) files in the directory, all called by the same program (different call command parameters per different target structures). Do I make sense?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to read file and run multiple jobs

I have a txt file line1 line2 line3 $!/bin/sh cat /tmp/lus.txt | while read line do esxcli storage vmfs unmap -u $lin -n 4000 done this works but does in one line at a time. how do I do all lines at once simutaeously? Please use CODE tags as required by forum rules! (4 Replies)
Discussion started by: tdubb123
4 Replies

2. UNIX for Beginners Questions & Answers

How to run multiple cron jobs?

I have two scripts which I'm tying to run one after the other- this is what I've tried: 00 14 * * * /path/one.sh && /path/two.sh I've also tried putting each script on a different line: 00 14 * * * /path/one.sh 00 14 * * * /path/two.sh Can this be done? (1 Reply)
Discussion started by: $shell_Learner
1 Replies

3. UNIX for Beginners Questions & Answers

A single script to run multiple scripts

Hi , Can someone help! I need a shell script to run multiple scripts by using single shell script, incase any one of the scripts fails, it should get exit and after trouble shooting if we re-execute it, it should start from the failed script. I have a written a scripting till the... (1 Reply)
Discussion started by: anniesurolyn
1 Replies

4. Shell Programming and Scripting

Shell script to run multiple jobs and it's dependent jobs

I have multiple jobs and each job dependent on other job. Each Job generates a log and If job completed successfully log file end's with JOB ENDED SUCCESSFULLY message and if it failed then it will end with JOB ENDED with FAILURE. I need an help how to start. Attaching the JOB dependency... (3 Replies)
Discussion started by: santoshkumarkal
3 Replies

5. Shell Programming and Scripting

UNIX script to check multiple jobs runninng status

Hi Folks, Please help me ,I need a unix shell script to check for multiple jobs running. if there are multiple backup Jobs running then it should be trigger an email . Thanks, Anand T (1 Reply)
Discussion started by: nandu67
1 Replies

6. Shell Programming and Scripting

Run one script on multiple files and print out multiple files.

How can I Run one script on multiple files and print out multiple files. FOR EXAMPLE i want to run script.pl on 100 files named 1.txt ....100.txt under same directory and print out corresponding file 1.gff ....100.gff.THANKS (4 Replies)
Discussion started by: grace_shen
4 Replies

7. UNIX for Dummies Questions & Answers

Run one script on multiple files and print out multiple files.

How can I run the following command on multiple files and print out the corresponding multiple files. perl script.pl genome.gff 1.txt > 1.gff However, there are multiples files of 1.txt, from 1----100.txt Thank you so much. No duplicate posting! Continue here. (0 Replies)
Discussion started by: grace_shen
0 Replies

8. Shell Programming and Scripting

Using a script to define variables and run multiple other scripts in succession.

I'm pretty new to scripting in Korn shell so please forgive me... What I'm trying to do is to create a script that calls multiple other ksh scripts and defines variables for text files. I need it to define my user defined variables (file paths, date & time stamps, etc that are currently in... (1 Reply)
Discussion started by: bluejwxn8
1 Replies

9. UNIX for Dummies Questions & Answers

Sh script to run multiple php scripts

I wrote a .sh script to run 5 php scripts. The problem is that it's running 1 then 2 then 3 in that order .... I want it to execute all 5 at ONCE.... nohup php /home/script1/script1.php && nohup php /home/script2/script2.php && nohup php /home/script3/script3.php && nohup php... (1 Reply)
Discussion started by: holyearth
1 Replies

10. Shell Programming and Scripting

Check if script run by a user directly or via other scripts

Hi, i have a script 'a.sh' that should be called only by certain scripts like b.sh, c.sh Inside a.sh, how can i determine 1) if this script was run directly from command prompt (or scheduler) 2) if called via other scripts? Is there an easy way to get parent process name (not just pid),... (2 Replies)
Discussion started by: ysrinu
2 Replies
Login or Register to Ask a Question