I'm doing an script that check configuration files. In order to check multiple lines at once I'm using pcregrep. When i use it in command line everything works great.
When I put it inside a function it does not fidn the pattern.
This is my function
function pcregrepF() {
echo pcregrep -M "$string" $path
if `pcregrep -M $string $path`; then
echo "$path --> $string_msg is configured OK"
else
echo "$path --> $string_msg is NOT configured correctly"
fi
}
The echo pcregrep -M "$string" $path
it's just a control to verify that it takes the pcregrep
command take the good variables
when I execute the file with the function I have the following in the console
/etc/yum.repos.d/nginx.repo --> 'NGINX repository' repository is NOT configured correctly
Funny thing : When I copy-paste the result of
echo pcregrep -M "$string" $path
shown in the console, that is :pcregrep -M ".*[nginx]*\n.*name=nginx.*.repo*\n.*baseurl=http://nginx.org/packages/centos/.*.releasever/.*.basearch/*\n.*gpgcheck=0*\n.*priority=1*
It works like a charm
UPDATE : Actually I'm trying to parse the regex and paths from a CSV file, the lines below are, the columns names and an exemple of the content of the file :
function,string,string_msg,path,package,space,
pcregrepF,".*[nginx]*\\n.*name=nginx.*.repo*\\n.*baseurl=http://nginx.org/packages/centos/.*.releasever/.*.basearch/*\\n.*gpgcheck=0*\\n.*priority=1*\\n.*enabled=1",NGINX repository,/etc/yum.repos.d/nginx.repo,, ,
This the function that reads the CSV file and in fonction of the first column it calls one function or another :
# Execute CSV - Read CSV file line by line and execute commands in function of parameters that are read
function executeCSV() {
file=/home/scripts/web.csv
while IFS="," read function string string_msg path package space
do
$function $string $string_msg $path $package
done < $file
}
executeCSV
I hope that it can help to troobleshoot the problem.
What I'm missing ???????
Thank's in advance