how to access variables in a config file inside a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to access variables in a config file inside a shell script
# 1  
Old 06-15-2009
how to access variables in a config file inside a shell script

I'm writing a shell script. I want to put the variables in a separate config files and use those inside my script.
e.g. the config file (temp.conf)will have the values like
mapping=123
file_name=xyz.txt
I want to access these variables in temp.conf(i.e. mapping and file_name) from inside the shell script.
The purpose of the shell script is to check the value of the variable "mapping" .
If mapping=123 then it'll create a file with name equivalent to the value assigned to the
variable file_name (i.e. xyz.txt in this case)
I'm new to Unix Shell scripting.
Could you help me solving this problem?
# 2  
Old 06-15-2009
hope below can help you some

Code:
while read line;do
eval $line
done < a
echo $mapping
echo $file_name
if [ $1 -eq $mapping ];then
touch $file_name
else
echo "mapping code is incorrect"
fi

# 3  
Old 06-16-2009
The way to do this is...
temp.conf should look like this...
Code:
export mapping=123
export file_name=xyz.txt

now in the script you can use these variable once you execute the conf file...
Code:
. temp.conf
echo $mapping
echo $file_name

# 4  
Old 06-16-2009
Code:
awk -F"=" '$1=="mapping" && $2=="123"{
 getline
 filename = $2
 print filename
}' file

# 5  
Old 06-16-2009
read the external config file and assign the values to variables inside shell script

Hi,
Just explaining the requirement more elaborately:

data in temp.conf :
----------
a=10
b=7
c=8

My requirement:
----------------
check the temp.conf file using awk
find the value of "a" and assign the value to variable "ram" i.e. ram=value of a i.e.10
find the value of "b" and assign it to the variable "shaym" i.e. shyam=value of b i.e.7

find the value of "c" and assign it to the variable "hari" i.e. hari=value of c i.e.8

Could anyone please post the code snippet?
# 6  
Old 06-16-2009
Code:
ram=`grep 'a=' temp.conf | awk -F"=" '{print $2}'`
shyam=`grep 'b=' temp.conf | awk -F"=" '{print $2}'`
hari=`grep 'c=' temp.conf | awk -F"=" '{print $2}'`

# 7  
Old 06-16-2009
thanks

Thanks all of you.
Thanks a lot @rakeshawasthi
it works...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

2. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

3. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

4. Shell Programming and Scripting

Update config file using shell script in Solaris 5.10

hi I need to update the value in config.txt value using shell script example: lets say a value in config.txt file is as SEQUENCE=1 after some iteration as the loop ends , the SEQUENCE should get update in the config.txt file with a new value of SEQUENCE=2. also , can anyone please help me... (7 Replies)
Discussion started by: ravidwivedi2288
7 Replies

5. Shell Programming and Scripting

Running .sh file inside a shell script

Hello, You might help a newbie like me, I am trying to run a .sh inside my shell script. After running that I need to execute below commands. Here's how my scripts looks like. Hope you can help: #!/bin/sh cd $ORACLE_HOME/owb/bin/unix ./OMBPlus.sh ---> goes to OMB+> directory cd... (10 Replies)
Discussion started by: aderamos12
10 Replies

6. Shell Programming and Scripting

How to access outparameter of a Procedure called inside a shell script?

Hi I am calling a PLSQL procedure inside a shell scipt. How to access out paramters of this procedure inside the mail shell script. I am using below peiece of code. echo " inside PKG validation" `sqlplus -s login/password@database <<EOF set heading off set... (6 Replies)
Discussion started by: karnatis
6 Replies

7. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

8. Shell Programming and Scripting

Edit a config file using shell script

I need to edit a config file using shell script. i.e., Search with the 'key' string and edit the 'value'. For eg: below is what I have in the config file "configfile.cfg". Key1=OldValue1 Key2=OldValue2 I want to search for "Key1" and change "OldValue1" to "NewValue1" Thanks for your... (7 Replies)
Discussion started by: rajeshomallur
7 Replies

9. Shell Programming and Scripting

How to parse config variables from external file to shell script

How do i use a config.txt to recursively pass a set of variables to a shell script eg my config.txt looks like this : path=c://dataset/set1 v1= a.bin v2= b.bin path=c://dataset/set2 v1= xy.bin v2= abc.bin .................. and so on . and my testscript : (2 Replies)
Discussion started by: pradsh
2 Replies

10. Shell Programming and Scripting

How to access the C program variables in shell script

hi I wanted to access the C program variables in shell script. This script is called from the same C program. What are the ways in which i can access variables thankx (3 Replies)
Discussion started by: bhakti
3 Replies
Login or Register to Ask a Question