Hi All,
Need your help to fix one script.
Main agenda is:
1. Read a property file.
2. Delete all files in directory except the name from Property file.
I am trying to read property file for value then deleting all files from directory except THAT value/name.
I have tried so far as below:
Property File i.e., earBuild.properties
Code:
#EAR Names
earName=XYZ.ear
OR
Property file can be with Multiple Ear names as:
Code:
#EAR Names
earName=XYZ.ear
earName=ABC.ear
I have written below shell script but loop is deleting all files in directory.
Code:
#!/bin/bash
echo "Reading property file at `pwd`"
ls -lrt
find /tmp/s/earProps/ -name earBuild.properties
FILE_NAME="earBuild.properties"
echo "EAR property file is: $FILE_NAME"
EARPATH="/tmp/s/props/ears/"
# Key in Property File
KEY="earName"
# Variable to hold the Property Value
prop_value=""
getProperty()
{
prop_key=$1
prop_value=`cat ${FILE_NAME} | grep ${prop_key} | cut -d'=' -f2`
}
getProperty ${KEY}
echo "KEY = ${KEY} ; Value = " ${prop_value}
for i in ${prop_value}; do
find $EARPATH -type f ! -name $i -exec rm -rf {} \;
echo "Value of I in loop is $i"
done
I am no bound to use find or rm or even for loop. Looking for the solution.
Appreciate help in advance.
Thanks