Read env variables from argument file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read env variables from argument file
# 1  
Old 12-24-2010
Read env variables from argument file

Hi,
I have a generic shell script (runBatchJob.sh) to read files (batchJob) with commands in them and execute the commands by reading the batchJob file as below
Code:
./runBatchJob.sh batchJob

batchJob file
Code:
$BATCHDIR/execute_procedure.sh
$DATADIR/collectData.sh
$OTHER_ENV_VAR/doSomething.sh

Now my problem is I'm perfectly able to execute each of the above commands from runBatchJob.sh, $BATCHJOB being replaced by /home/batchDir and so on and so forth.

But when I read the commands out of an argument file in my shell script $BATCHJOB doesn't get replaced at all and I cant run the command. When I echo the statement it prints fine.

Actual code of runBatchJob.sh
$1 being above batchJob file
Code:
i=1;
while [ $i -le `wc -l $1 | cut -d" " -f8` ]
    do
        echo Running `head -$i $1 | tail -1`; 
        echo `head -$i $1 | tail -1`;    
        `head -$i $1 | tail -1`;
        i=`expr $i + 1`;
   done;

Please help Smilie

---------- Post updated at 11:54 AM ---------- Previous update was at 11:39 AM ----------

Ok below worked Smilie
eval `head -$i $1 | tail -1`;
# 2  
Old 12-24-2010
I believe in above while loop, you are trying to read each line one by one from batchJob and execute that line. If so, in place of above while loop, you may try:
Code:
while read line; do
   echo "Running $line"
   eval $line
done < $1

# 3  
Old 12-24-2010
what u need exactly can u explain the question breifly
# 4  
Old 12-24-2010
Thanks Anurag but there are additional lines in the file so need to skip them, I actually included only the lines which were needed.

Raja I needed to fetch commands to be executed in a shell script from and input argument file but as the commands being fetched had env variables, they were not being evaluated hence the eval came to the rescue
# 5  
Old 12-24-2010
You didn't mention anything about which line to execute and which line to skip. Above while loop will execute all lines in batchJob file.
Pls give some sample of batchJob and some pattern/rule to decide when to execute a line and when not.
# 6  
Old 12-24-2010
Ok here is a simple one
first line is name of the batch Job
2nd is the name of the individual job, 3rd is the command for 1st job, 4th is again the name of 2nd individual job, 5th is the 2nd job and ...
Code:
myBatchJob
US_SASFeedExtract
$BATCHDIR/execute_procedure.sh prc_generate_sas_bk_feed "(p_success)"
US_SASFeedDataMoveToHist
$BATCHDIR/move.sh "$DATAOUTDIR/GCMSSAS.txt" "$HISTDIR/GCMSSAS.txt$GCMS_DATETIMESTAMP"
US_SASFeedDEODMoveToHist
$BATCHDIR/move.sh "$DATAOUTDIR/GCMSEOD.txt" "$HISTDIR/GCMSEOD.txt$GCMS_DATETIMESTAMP"
US_EmailSASFeed
$BATCHDIR/mail_text.sh $DATAOUTDIR 'GCMSSAS.txt' 'abhijit@xyz.com' "GCMS UAT - SAS Feed File"

Acha in a different note can I have the same batchFeedFile in form of XML and can I read the XML in unix to process it?
# 7  
Old 12-24-2010
Why dont u include echo massages in your batch job itself and then simply run that file.

Code:
myBatchJob
US_SASFeedExtract
echo "Runnig excute_procedure.sh"
$BATCHDIR/execute_procedure.sh prc_generate_sas_bk_feed "(p_success)"
US_SASFeedDataMoveToHist
echo "Runnig move.sh"
$BATCHDIR/move.sh "$DATAOUTDIR/GCMSSAS.txt" "$HISTDIR/GCMSSAS.txt$GCMS_DATETIMESTAMP"
US_SASFeedDEODMoveToHist
$BATCHDIR/move.sh "$DATAOUTDIR/GCMSEOD.txt" "$HISTDIR/GCMSEOD.txt$GCMS_DATETIMESTAMP"
US_EmailSASFeed
$BATCHDIR/mail_text.sh $DATAOUTDIR 'GCMSSAS.txt' 'abhijit@xyz.com' "GCMS UAT - SAS Feed File"

Than simply execute this file in runBatchJob.sh
Code:
..
code
..
sh myBatchJob
..
code
..

R0H0N
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. How to Post in the The UNIX and Linux Forums

Read a json file passed as cmd line argument

usage: myscript.sh config.json config.json: { "HOST":"abc", "DB_NM":"xyz", "USR_NM":"asd", "PWD":"xxx", ......... ......... ......... ........ } myscript.sh: (2 Replies)
Discussion started by: RGRT
2 Replies

2. Shell Programming and Scripting

Env variables in script

Hi All, I have script and it's hardcoded the script ca invoke in user home dir and logs will be redirected to home dir of user. how to make the same script will be invoke from /usr/bin with out chg the logs and other functions path from /user/homedir . code is below: pls check how to... (1 Reply)
Discussion started by: saku
1 Replies

3. Red Hat

how to use env variables within ed

i have a file that i need to edit and replace a single value with another. so i have two variables, $oldvalue and $newvalue but below doesn't work: ed file.txt << EOF ,s/$oldversion/$newversion/g wq EOFi presume it's the $ that is the issue since it's actually special to ed. any suggestions?... (1 Reply)
Discussion started by: crimso
1 Replies

4. Solaris

env variables again

What is the difference between ${variable} and $variable when used in a script? (2 Replies)
Discussion started by: orange47
2 Replies

5. UNIX for Dummies Questions & Answers

How to update env variables.

I am newbie on Unix system and seek help for updating env variables. The condition is like this: On Unix server, I log in as oracle user (this is the super for database on Unix), I type > env all envirnment variables show up. I saw one variable DBA_LIST contains a few email addreses. I need... (2 Replies)
Discussion started by: duke0001
2 Replies

6. UNIX for Dummies Questions & Answers

set env variables in a new xterm

Hi, I have a script that sets some env variables. I want to source the script in a new xterm and after the script execution is over, the xterm has to be alive with the env variables set according to the script. I tried xterm -e "source ./myscript;tcsh" & The variables are getting set... (3 Replies)
Discussion started by: chaitubek
3 Replies

7. Shell Programming and Scripting

Getting the value of env variables

Hi, I want to get the value of the env varables using the ksh script. All the env variables are stored in a file. Eg. file1 $INPATH $OUTPATH myscirpt: for name in `awk { print $1 } file1` do cd $name done i'm getting the error like $INPATH not found. in the same script... (1 Reply)
Discussion started by: vij_krr
1 Replies

8. Shell Programming and Scripting

awk using env variable as search argument

Hello, I have a file like was123##abcdefg abddef was123##xuzaghg agdfgg was133##CGHAKS DKGJG from the file i need to print the line after ## where the serach value is passed by an env variable called luster (which is currently set to was123): i tried using the below code but it... (7 Replies)
Discussion started by: amit1_x
7 Replies

9. UNIX for Advanced & Expert Users

Ksh - Env. Variables ??

Hey all, I have been using Ksh and in that I am setting Environment variables. To set Env. Variables I have created my own file "BuildScript.sh" in which i have written : export CLASSPATH=/somedir/some other dir/file:. export PATH=/some dir/file:. But when i am calling this... (4 Replies)
Discussion started by: varungupta
4 Replies

10. Shell Programming and Scripting

export env variables

hi i want to write a shell script to set environment variables . But i am not been able to set that for the current shell instead i have to spawn a new shell. Is there a way to set the env variable for the current shell using shell script in bash shell ? Thnx (2 Replies)
Discussion started by: varun.81
2 Replies
Login or Register to Ask a Question