Shell Programming

Hi,

I am using two files - one file contains list of service name , other file contains commands for each of these service name .

I have to read each service name and check this string in 1.cfg file , if it exists , then i have to read another file (commands file ) and take the string and check if it is in 2.cfg file . i have to continue till end of the line in the files.

Note : it should be one after the another .

I wrote a script which is has below

for x in `cat service_list
do
grep $x 1.cfg  > /dev/null 2>&1
 if [ $? -eq 0 ]
                  then
echo "$x exits"
echo "Now checking another file"
fi
for y in `cat command_list`
do
grep $y 2.cfg > /dev/null 2>&1

if [ $? -eq 0 ]
                  then
echo "$y exists"
fi
done
done

here the inner for loop executes completly first , checks all commands and then goes to outer for loop . but my requirement is to check service then check command . and it should repeat like check service and then command.

Please help

Thanks

Please use code tags as required by forum rules!

Not clear. Your snippet loops through the entire command file once for EACH service entry. Regardless of the service's existence in file1. Which might become lengthy.

Please be way more detailed and specific - what exactly do you want to achieve? What's the relation between services and commands? Do you know about the -f option to grep ?

here are the details :
example
my service file list is as below

hostname
region name
...
...
so on

for each service , my command list file is having corresponding command entry as below

check_hostname
check_region

i have to write a validation script to which
a. read service file list (one by one ), check that in 1.cfg file then
b. read command file list ( one by one ) , check that in 2.cfg if it exists.

Repeat a and b step for each time.

hope this time my requirement is clear.

Thanks in advance.