using config file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using config file
# 1  
Old 09-05-2006
using config file

Hello

I got script where is defined path name, connect string to database and
name of the log file.

I would like to create a new config file which will be consists of these path name, connect string and name of the log file.

But I don't know how to use this config file into the main script?
Or how to create a nice config file for other use?


For example of config file:
# TEMPORARY INCREMENT FILE
pivot='/tmp/.fileCount'

# CONNECTING STRING
USERNAME aaaaa
PASSWORD bbbbb
DBNAME xxxxx
---------------------------------------------

Thanks a lot
# 2  
Old 09-07-2006
I think this is what you are looking for....let me know if it is not.
(Assuming you are using sh or ksh)
in your config file do stuff like....

# This is the configuration file for XXX
# Please place double quotes around all entries that have spaces in there
# values after the equals sign, ie FileList="file1 file2 file3"
#
#This parameter is the name of the logfile
logfile=/tmp/log.out
#
#
# TEMPORARY INCREMENT FILE
pivot='"tmp/.fileCount"
#
# CONNECTING STRING
# Place user name here
USERNAME=aaaaa
#
#Place passwd here
PASSWORD=bbbbb
#
#Place Dbname here
DBNAME=xxxxx
#
#this is the end of the config file

Now in your MAIN script all you do is....

#!/bin/sh
# This is my main script
# First need to source the config file
# if we can not read the cfg then exit!
if [ -r /path/to/config.cfg ]
then
# getting config file
. /path/to/config.cfg
else
echo "Can not read config.cfg
exit 99
fi

echo "$logfile"
echo "$pivot"
echo "$USERNAME"
echo "$PASSWORD"
echo "$DBNAME"


You can use "." or the "eval" inside your main script to source the information from your config file depends how and what you are sourcing

Hope this is what you are after
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Apache virtual host config vs global config problem

Hi folks, I am trying to configure Apache webserver and also a virtual host inside this webserver. For Global server config: /var/www/html/index.html For virtual host config: /var/www/virtual/index.html Both client10 & www10 are pointing to 192.168.122.10 IP address. BUT, MY... (1 Reply)
Discussion started by: freebird8z
1 Replies

2. UNIX for Dummies Questions & Answers

Generating a Config File

HI, I want to append some configuration statements to the existing file in unix to it's 3 line , 7th line and 28 line. There is a file generated by our system job, to this I need to add some lines as mentioned below. DIR=/usr/CDR - line 3 Source=/usr/src - line 7 Target=/usr/tgt - line... (2 Replies)
Discussion started by: mora
2 Replies

3. UNIX Desktop Questions & Answers

Gnome config file

Hi Guys If i go to systems -> Preferances -> Look and Feel -> Windows i can click on the radio box for "Super (or "Windows Logo") is there a config file i can change it in instead i can not find it thanks Adam (0 Replies)
Discussion started by: ab52
0 Replies

4. Shell Programming and Scripting

how to send config file

hi all please give me some idea about how to send xml file from one c++ pgm to other pgm. (1 Reply)
Discussion started by: shubhig15
1 Replies

5. 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

6. Shell Programming and Scripting

parsing config file to create new config files

Hi, I want to use a config file as the base file and parse over the values of country and city parameters in the config file and generate separate config files as explained below. I will be using the config file as mentioned below: (config.txt) country:a,b city:1,2 type:b1... (1 Reply)
Discussion started by: clazzic
1 Replies

7. Shell Programming and Scripting

Parsing config file

Hi All, I have a requirement to parse a file. Let me clear you all on the req. I have a job which contains multiple tasks and each task will have multiple attributes that will be in the below format. Each task will have some sequence number according to that sequence number tasks shld... (0 Replies)
Discussion started by: rajeshorpu
0 Replies

8. Shell Programming and Scripting

Read from a config file.

Hello All, I have a config file which has the following data : export DBCHECKSUM001="/home/srvcdesk/DBCheckSum/DBCheckSum001.cfg" export DBCHECKSUM002="/home/srvcdesk/DBCheckSum/DBCheckSum002.cfg" export DBCHECKSUM003="/home/srvcdesk/DBCheckSum/DBCheckSum003.cfg" export... (1 Reply)
Discussion started by: Veenak15
1 Replies

9. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies

10. Shell Programming and Scripting

getting data from config file

pls help.. I need to get the ESSID value for athx this is the config file.. pls help (7 Replies)
Discussion started by: esham
7 Replies
Login or Register to Ask a Question