LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Reading a property file through shell script??? (https://www.linuxquestions.org/questions/linux-newbie-8/reading-a-property-file-through-shell-script-906482/)

sukhdip 10-05-2011 12:36 AM

Reading a property file through shell script???
 
Hi!
i need a script that can read a property file.
i.e., A script to read a "property" from property file.
Read the property value and
based on value of property, decide whether to start the some dataload activity or not.

Its urngent. Can anyone help me out???

corp769 10-05-2011 01:19 AM

Hello,

This makes no sense to me whatsoever. What exactly are you trying to do here? And what property file are you talking about? Also, what is this "dataload activity" you are talking about?

Cheers,

Josh

sukhdip 10-05-2011 01:59 AM

1 Attachment(s)
Hey! its kind database activity in IBM WCS.

There are java properties files which are having key and action related to that.(For example am attaching a property file,its like text file can open with notepad)

Here is the problm: Script should read that property file and if the value of property file is YES, then it should start the activity of dataload.or more precisly its should return YES valuse to crontab which will start the dataload, which i will configure in crontab.
If property file value is NO. then not to start dataload.

If you understand n how much u understand. then please help me out.


Please remove txt from extension as to get properties file.

sukhdip 10-05-2011 02:07 AM

Or can you please provide me a script that will read a prorperty file.....???
Just to read property file.

lithos 10-05-2011 02:27 AM

Hi

If you have a file with 'example' contents:
Code:

#
# these all are the comments as per file.
# Property File
#

DATA_LOAD=YES

then you can get the value from file like:
Code:

# grep -i 'DATA_LOAD' example.properties.txt  | cut -f2 -d'='


Output:
YES

or in script ( let's call it "testproperty.sh":
Code:

#!/bin/sh
FILE=/var/tmp/testproperties/example.properties.txt

ACTION=$(grep -i 'DATA_LOAD' $FILE  | cut -f2 -d'=')

if [ "$ACTION" = "YES" ]
then

... do something you need to when answer is Yes ...

elif [ "$ACTION" = "NO" ]
then

... action to take if No ...
# for example print out the value
echo "$ACTION"

# if no match
else
echo "$ACTION"

fi
#end of script

This script assumes that you have only one ( 1) line with:
Code:

DATA_LOAD=YES
or DATA_LOAD=NO

sukhdip 10-05-2011 04:05 AM

lithos you rocks buddy!!

sukhdip 10-05-2011 09:07 AM

Hi!

Like I have to run a batch file named dataload.bat.. which will perform further actions of loading data. which might be scheduled in crontab to run.
what i should use or how i should make use of this script that will run that crontab or dataload.bat file if and only if the status of property file is YES. I have to put that under If condtion..right..
coz just new to this scripting i dn't know much about it.

So please guide me..

Thanks,

lithos 10-05-2011 09:31 AM

well, since I don't know IBM WCS system I can only assume that "dataload.bat" is for Windows, which I'm not familiar with scripting, only Linux.

but anyway, you can insert the line to 'run' your script into the code "testproperty.sh":
Code:

#!/bin/sh
FILE=/var/tmp/testproperties/example.properties.txt

ACTION=$(grep -i 'DATA_LOAD' $FILE  | cut -f2 -d'=')

if [ "$ACTION" = "YES" ]
then
# here you run your script
$(/path/to/your_script/dataload.bat)


elif [ "$ACTION" = "NO" ]
then

... action to take if No ...
# for example print out the value
echo "$ACTION"

# if no match
else
echo "$ACTION"

fi
#end of script

and CRONTAB is not meant to be run by script, that's why it's scheduled running.

You will do best if this script is running with Crontab and inside this script you call the "dataload.bat" like posted above.

nandi 10-05-2011 09:50 AM

Thanks a lot for your valuable reply. I will let you know after running this system.

Yeah at last I'm going to run the whole things on AIX.

I will post here by tomorrow.


All times are GMT -5. The time now is 02:28 PM.