Read env variables from argument file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read env variables from argument file
# 8  
Old 12-24-2010
I understand that you need to execute lines having unix script name i.e. *.sh. Will it hold true across the file?If yes, then good. Following will execute only those lines where 1st column ends with ".sh"
Code:
awk '$1 ~ /.*.sh$/' $1 | while read line; do
   echo "Running $line"
   eval $line
done

Yes, You may put batch file in form of XML. Put a proper tag name for command to run and script can read value inside that tag and execute that.
# 9  
Old 12-24-2010
Gr8 thanks Anurag, but cud you plz show a small example with the below XML

Code:
<batchJob>
<name>myBatchjob</name>
<jobs>
<job>$BATCHDIR/execute_procedure.sh</job>
<job>$BATCHDIR/move.sh</job>
<job>$BATCHDIR/mail_text.sh</job>
</jobs>
</batchJob>

# 10  
Old 12-24-2010
Let's say you make your XML job file as:
Code:
<batchJob>
<name>myBatchjob</name>
<jobs>
<job>
$BATCHDIR/move.sh "$DATAOUTDIR/GCMSSAS.txt" "$HISTDIR/GCMSSAS.txt$GCMS_DATETIMESTAMP"
</job>
<job>
$BATCHDIR/mail_text.sh $DATAOUTDIR 'GCMSSAS.txt' 'abhijit@xyz.com' "GCMS UAT - SAS Feed File"
</job>
<job>
$BATCHDIR/execute_procedure.sh prc_generate_sas_bk_feed "(p_success)"
</job>
</jobs>
</batchJob>

Then following should do the needful:
Code:
awk '/\<job\>/,/\<\/job\>/ if(substr($1,length($1)-2)==".sh") print}' $1 | while read line; do
   echo "Running $line"
   eval $line
done

Here only requirement is:
put your unix script command to be executed inside <job> and </job> as below
Code:
<job>
YOUR COMMAND
</job>

# 11  
Old 12-24-2010
Ok I'll try above and get back thanks Smilie
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