[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 414
  • Last Modified:

Bash script to read from external file for execution

Hi Experts

I want to create a scripts that reads configurations that will be uploaded to an application server. The problem is I dont know how to call the values in a file. The script will work as follows

Scripts reads the configuration file which contains a hostname, target and values under it, i.e
==============================
Hostname
target

values to be executed
=============================

I want to be able to read the values in this file, how do I achieve this?

Thank you for your assistance.
0
jw124210
Asked:
jw124210
  • 4
  • 2
1 Solution
 
ozoCommented:
cat file

or do you want to do anything else with the values in the file?
0
 
jw124210Author Commented:
Yes, I want to use the values to setup an application server configuration. The file looks like the one below, I have put in brackets what this configuration file does. Please not this will be executed by a script:

# This is a configuration file for environment setup
#===================================
hostname%hostname.test.com (get the hostname to use inside script)
portnumber%4848 (get the port number to use inside script)
#===================================

%D%START-CONNPOOL (this is the delimiter which must be mapped to the actual command)
connectionpool1 (these are the pools that will be created, from connectionpools1 to 4)
connectionpool2
connectionpool3
connectionpool4
%D%END-CONNPOOL (end execution when it reaches this line, and move to the next START)

%D%START-CONNFACT
%conf_in
targets%target1%target2%target3
jms/testPool1%jms/conFactory1
jms/testPool2%jms/conFactory2
jms/testPool3%jms/conFactory3
jms/testPool4%jms/conFactory4
jms/testPool5%jms/conFactory5
%D%END-CONNFACT

%D%START-ADMINOBJ
%conf_in
target1%target2%target2%target3
jms/tAdminobject1%tpcAdminObject1%Topic
jms/tAdminobject2%tpcAdminObject2%Topic
jms/tAdminobject3%tpcAdminObject3%Queue
jms/tAdminobject4%tpcAdminObject4%Queue
jms/tAdminobject5%tpcAdminObject5%Topic
%D%END-ADMINOBJ

%D%START-JBIVAR
%conf_in
# execute the below with resource references
target1%target2%target3%target4
# stop binding component
# start binding component
# wait for bing component to finish then proceed
%D%END-JBIVAR

%D%START-JVMOPT
jvm_options
conf_in
target1%target2%target2%target3
%D%END-JVMOPT

%D%START-SYSPROP
system_properties
conf_in
target1%target2%target2%target3
%D%END-SYSPROP

%D%START-DEPLIB
dep_libs
target1%target2%target2%target3
%D%END-DEPLIB

Please let me know if this makes sense.
0
 
ozoCommented:
Do you just want to put those values into bash script variables?
something like:
while read ; do
case $REPLY in
hostname%* ) hostname=${REPLY#hostname%} ;;
portnumber%* ) portnumber=${REPLY#portnumber%} ;;
%D%END-CONNPOOL* ) CONNPOOLSTART=0 ;;
esac
if (( $CONNPOOLSTART )) ; then
CONNPOOL+=$REPLY
fi
case $REPLY in
%D%START-CONNPOOL* ) CONNPOOLSTART=1 ;;
esac
done < Q_27830839.conf

echo hostname=$hostname
echo portnumber=$portnumber
echo CONNPOOL=$CONNPOOL
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
jw124210Author Commented:
The variables and values will be in a separate file, the script will read this file with contents above. I want to separate script from the configuration I will be reading.
0
 
jw124210Author Commented:
Yes, I want to put the values into a bash script variable
0
 
jw124210Author Commented:
apologies for the delay, I was busy on a project. Thank you it worked well, I had to ad a few more steps in the script.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now