Fetching variable from config file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fetching variable from config file
# 1  
Old 07-23-2013
Fetching variable from config file

I am using . .profile in my script below
I want to fech it it from my configuration file .id_pass_file.txt(it has all user_name and passwords)
how can i do this
Code:
PROFILE_PATH=. .profile
AND IN MY SCRIPT 
$PROFILE_PATH
IS THIS CORRECT

Code:
#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y  %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR

## /path/to/profile .This is required for crontab to work as bip.sh  uses environmental variables.
. .profile

LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file 
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID


### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<<EOF>$CUR_DIR/sql_output.txt
set feedback off
set heading off
select distinct account_no from adj  WHERE ADJ_TRANS_CODE=-2401  and request_status=1  and bill_ref_no=0
order by account_no;
EOF


if [ $? -eq 0 ] 
then 
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are  "



if [  ! -s  "$CUR_DIR/sql_output.txt" ]
then
echo "No account number for bad debt" 
else
for i in `cat $CUR_DIR/sql_output.txt`
do
echo "bip $i is running"
sh  $SCRIPT_DIR/bip.sh 01 0 $i >  $CUR_DIR/bip_log_1.txt
sleep 180
done
fi


###Removing temporary log files generated 

if [ -f  "$CUR_DIR/bip_log_1.txt" ]
then
 rm  "$CUR_DIR/bip_log_1.txt"
 echo "file bip__log_1.txt removed"
fi

if [ -f "$CUR_DIR/sql_output.txt" ]
then
 rm  "$CUR_DIR/sql_output.txt"
 echo "sql_output.txt removed"
fi

rm  $CUR_DIR/error.log

# 2  
Old 07-23-2013
You may need to fully qualify the path the your .profile. Consider also that the default path created by logging on may be different to that created by a cron job.

I would also quote the value if you are going to set PROFILE_PATH:-
Code:
PROFILE_PATH=". /home/myuser/.profile"


Do either of these suggestions help?

Robin
Liverpool/Blackburn
UK
# 3  
Old 07-23-2013
Quote:
Originally Posted by rbatte1
You may need to fully qualify the path the your .profile. Consider also that the default path created by logging on may be different to that created by a cron job.

I would also quote the value if you are going to set PROFILE_PATH:-
Code:
PROFILE_PATH=". /home/myuser/.profile"


Do either of these suggestions help?

Robin
Liverpool/Blackburn
UK
Hi i can see two profile paths
locations are
Code:
/.profile

and

Code:
echo  $HOME/.profile
/A/B/.profile

Which profile to use .Please enlighten me.My script is working fine for /.profile
# 4  
Old 07-23-2013
I would assume that /.profile is going to be the profile for the root user (and any other user that has home directory of /

You may not be able to use the value from $HOME in your cron job though.



Robin
# 5  
Old 07-23-2013
Quote:
Originally Posted by rbatte1
I would assume that /.profile is going to be the profile for the root user (and any other user that has home directory of /

You may not be able to use the value from $HOME in your cron job though.



Robin
So you mean i should use /.profile.i am in DEV enviroment .Hope it works in production tooSmilie

i followed your advice
PROFILE_PATH="/.profile"
But i am getting an error
/.profile not found
PROFILE_PATH=/.profile --this works fine though

rbatte please reply lol

Last edited by rafa_fed2; 07-23-2013 at 12:08 PM..
# 6  
Old 07-23-2013
Is .profile in /, yes or no? If not, it won't find it there, you'll need to tell it somewhere else.
# 7  
Old 07-23-2013
Quote:
Originally Posted by Corona688
Is .profile in /, yes or no? If not, it won't find it there, you'll need to tell it somewhere else.
In dev enviroment it is there.In production i dont know .Thats is my i am storing it in the configuration file.i will tell them to change it.
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

Access another variable config variable

Hi all, Please help me on my problem. I want to take a value of variable which the variable is in other file. variable.sh wesly=1 wina=2 wekin=3 variabletaker.sh source variable.sh echo $wesly when i run the variabletaker.sh the error result is like here error (3 Replies)
Discussion started by: weslyarfan
3 Replies

3. Shell Programming and Scripting

Query on fetching a value of variable in script

I have below 3 files in a directory : oktest.txt okcode.txt okfun.txt I was writing a small shell script to just print the names of three files where I took a variable a and assigned it a value ok. a=ok echo "Three files are : $atest.txt $acode.txt $afun.txt" But when I run... (3 Replies)
Discussion started by: simpltyansh
3 Replies

4. Shell Programming and Scripting

how to read the variable indivdually from config file

how to read the variable indivdually ( line by line ) in shell script eg : i have the config file where contain cat /home/user01/ilap/conf/input.conf node.txt node2.txt node3.txt i need to run script like /home/user01/ilap/exe/run.sh /home/user01/ilap/conf/input.conf ... (1 Reply)
Discussion started by: mail2sant
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

Parse config file data to script variable

I have a script with few pre defined variables. Also have a config file. Something like this. # config file # Define Oracle User MOD1_TAG=abcde MOD2_TAG=xyzabc MOD3_TAG=def I need to parse the config file and have each of the value copied to different variables. Please suggest what... (1 Reply)
Discussion started by: souryadipta
1 Replies

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

8. Shell Programming and Scripting

how to read the variable from config file

how to read the variable from config file eg: a.cfg below config file config file which contain a=`hostname` b=250 a.sh is shell script echo "$a and $b" if i run "a.sh 1.cfg" it works but when i declare N number of variable it wont works.. can u please suggest for that ? (1 Reply)
Discussion started by: mail2sant
1 Replies

9. Shell Programming and Scripting

Exporting variable from config file

Hi, I am exporting the environment variable from config file, but when I echo the variable it does not display any value. Here is the snippet of the code #!/bin/sh export ENVIRONMENT_ROOT_DIRECTORY="/cb/$ENVIRONMENT" echo $ENVIRONMENT_ROOT_DIRECTORY ${JAVA_HOME}/bin/java... (2 Replies)
Discussion started by: bhavnabakshi
2 Replies

10. UNIX for Dummies Questions & Answers

How to Read a config file and Assign to Variable

I have removeConfig file, it contains the dir paths for removing. I need to read line by line and assign to variable. any idea? (1 Reply)
Discussion started by: redlotus72
1 Replies
Login or Register to Ask a Question