Shell script compare all parameters in two files and display results


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script compare all parameters in two files and display results
# 1  
Old 11-16-2010
Error Shell script compare all parameters in two files and display results

Hi ,
I am not familiar with shell programming. I have a requirement like i have two files
.I need to compare the two files by comparing each parameter and i should produce 2 outputs.
1)i have around 35 parameters say i have one parameter name called db_name=dcap in one file and db_name=dcicr in another file.then i need to display the output stating the difference in db_name.
2)output2:There are some parameters say one parameter name memory_target= some value is only present in second file but not in first file.i need to check this parameter whether it is properly set or not if not ,produce the output stating parameter is not set.
3)output3:There are some deprecated parameters are there in my first file say there are 9 parameters.If these parameters are there in second file then i should generate a report stating these are deprecated no need to implement these items.
ex: i have a parameter called java_pool_size .if it is present in second file i should say that this parameter should not be implemented.
I would really appreciate your help in this script.Your inputs are always welcome.
I am trying from my end...Advance thanks to persons for their replies....

My OS:Susi linux 10.3.
# 2  
Old 11-16-2010
# 3  
Old 11-16-2010
Here requirement is different.Here we need to do check some specific parameters.
1)First one say i have parameter name db_block_size should be present in two files and if any mismatch found
we shold generate a report stating db_block_size parameter is differnet of it's not present in second file.
like that i need to check 35 parameters.
2)Second one:
There are some specific parameters present in second file i need to check for that parameters in second file
if it is not found i should generate a report stating say diagnostic_dest parameter is not present in second file.
3) Third one:There are some parameters present in file1 should not present in second file.if that is the case then i should
generate the report stating the parameter in file1 is present in file2. like that i have around 12 parametes.
I will provide you sample list:
for First one:
PARAMETERS TO BE VERIFIED WITH 9i vs 11g
db_block_size
db_cache_size
db_file_multiblock_read_count
open_cursors
cursor_sharing
background_dump_dest
core_dump_dest
user_dump_dest
for second requirement:
diagnostic_dest
db_unique_name
memory_max_target
memory_target
for Third requirement:
pga_aggregate_target
java_pool_size
large_pool_size
shared_pool_size
Thank you verymuch for your reply.Please let me know anything needs to be clarified
My OS:Susilinux 10.3
# 4  
Old 11-16-2010
This is hugly and not optimized but i think it does the work :

Code:
$ cat myfile
#!/usr/bin/ksh
f1=${1:-9i.ora}
f2=${2:-11g.ora}
printf "%-29s\t%40s\t%40s\n" "Param" "9i" "11g" >output.err
printf "%-29s\t%40s\t%40s\n" "Param" "9i" "11g" >output.ok
printf "%-29s\t%40s\t%40s\n" "Param" "9i" "11g" >output.all
while read p n
do
v9=$(grep $p $f1 | sed 's/.*=//' 2>/dev/null)
v11=$(grep $p $f2 | sed 's/.*=//' 2>/dev/null)
echo "p=$p v9=$v9 v11=$v11"
printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.all
case $n in
1)
        if [[ $v9 != $v11 ]]; then
echo "Warning : $p does not have the same values in $f1 and $f2 : missmatch !" >>output.err
                printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.err
        else
                printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.ok
        fi
;;
2)
if [[ -z "${v11}" ]]
then
        echo "Warning : $p is missing in file $f2" >>output.err
        printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.err
else
        printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.ok
fi
;;
3)
        if [[ -z "${v9}" ]]
        then
                echo "Warning : $p is missing in file $f1" >>output.err
                printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.err
        elif [[ -n "${v11}" ]]
        then
                echo "Warning : $p should not be in file $f2" >>output.err
                printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.err
        else
                printf "%-29s\t%40s\t%40s\n" $p ${v9:-"---"} ${v11:-"---"} >>output.ok
        fi
;;
esac

done<listparam

Note that listparam should have lines looking like <parameter_name> <number_of_the_requirment>
Code:
$ cat listparam
db_block_size 1
db_cache_size 1
db_file_multiblock_read_count 1
open_cursors 1
cursor_sharing 1
background_dump_dest 1
core_dump_dest 1
user_dump_dest 1
diagnostic_dest 2
db_unique_name 2
memory_max_target 2
memory_target 2
pga_aggregate_target 3
java_pool_size 3
large_pool_size 3
shared_pool_size 3
$

This will generate 3 output :

output.all (for an overview of all the parameter value in each of the file '---' if not found or empty)

output.err (with an error message saying what's going wrong)

output.ok (containing parameters that do not match your error requirements)

feel free to change the default value for f1 and f2 to some other filename that match yours.


Code:
$ cat output.all
Param                                                                 9i                                             11g
db_block_size                                                       8192                                            8192
db_cache_size                                                  838860800                                     15286272000
db_file_multiblock_read_count                                         32                                             ---
open_cursors                                                        1000                                             800
cursor_sharing                                                       ---                                             ---
background_dump_dest              '/oradata/9I/system/trace/bdump'               '/oracle/11G/saptrace/background'
core_dump_dest                    '/oradata/9I/system/trace/cdump'               '/oracle/11G/saptrace/background'
user_dump_dest                    '/oradata/9I/system/trace/udump'                '/oracle/11G/saptrace/usertrace'
diagnostic_dest                                                      ---                                             ---
db_unique_name                                                       ---                                             ---
memory_max_target                                                    ---                                             ---
memory_target                                                        ---                                             ---
pga_aggregate_target                                          1572864000                                     13652041000
java_pool_size                                                       32M                                             ---
large_pool_size                                                      10M                                             ---
shared_pool_size                                               268435456                                      1785000000
$ cat output.err
Param                                                                 9i                                             11g
Warning : db_cache_size does not have the same values in 9i.ora and 11g.ora : missmatch !
db_cache_size                                                  838860800                                     15286272000
Warning : db_file_multiblock_read_count does not have the same values in 9i.ora and 11g.ora : missmatch !
db_file_multiblock_read_count                                         32                                             ---
Warning : open_cursors does not have the same values in 9i.ora and 11g.ora : missmatch !
open_cursors                                                        1000                                             800
Warning : background_dump_dest does not have the same values in 9i.ora and 11g.ora : missmatch !
background_dump_dest              '/oradata/9I/system/trace/bdump'               '/oracle/11G/saptrace/background'
Warning : core_dump_dest does not have the same values in 9i.ora and 11g.ora : missmatch !
core_dump_dest                    '/oradata/9I/system/trace/cdump'               '/oracle/11G/saptrace/background'
Warning : user_dump_dest does not have the same values in 9i.ora and 11g.ora : missmatch !
user_dump_dest                    '/oradata/9I/system/trace/udump'                '/oracle/11G/saptrace/usertrace'
Warning : diagnostic_dest is missing in file 11g.ora
diagnostic_dest                                                      ---                                             ---
Warning : db_unique_name is missing in file 11g.ora
db_unique_name                                                       ---                                             ---
Warning : memory_max_target is missing in file 11g.ora
memory_max_target                                                    ---                                             ---
Warning : memory_target is missing in file 11g.ora
memory_target                                                        ---                                             ---
Warning : pga_aggregate_target should not be in file 11g.ora
pga_aggregate_target                                          1572864000                                     13652041000
Warning : shared_pool_size should not be in file 11g.ora
shared_pool_size                                               268435456                                      1785000000
$


Last edited by ctsgnb; 11-17-2010 at 06:52 AM..
# 5  
Old 11-17-2010
Thank you very much for your reply..
Here we are giving two files as input one is oracle 9i and another one is oracle 11g right..Where are you giving that?
I did n't get it exactly what listparams file contains? I mean parameters list from both files shall we need to give in list params file?
once again thank you very much for your timely reply....

---------- Post updated at 05:14 AM ---------- Previous update was at 04:48 AM ----------

Hi after running the scripts,These are the outputs i got it.
Code:
$ cat output.ok
Param                                                                 9i                                             11g
[hsar@catom-gmapdvl05 ~]$ cat output.err
Param                                                                 9i                                             11g
[hsar@catom-gmapdvl05 ~]$ cat output.all
Param                                                                 9i                                             11g


Last edited by vbe; 11-17-2010 at 09:34 AM.. Reason: code tags please
# 6  
Old 11-17-2010
Check that your listparam looks like mine (see my previous post, i have set some things in bold and red to bring your attention on those points)
in listparam,
<param> 1means : <param> should match the requirement 1
<param> 2means : <param> should match the requirement 2
<param> 3means : <param> should match the requirement 3

What name did you choose for the script ?
What name did you choose for the files you want to be analyzed ?
What name did you choose for the file containing the list of the parameters to check against the requirements ?

Last edited by ctsgnb; 11-17-2010 at 07:02 AM..
This User Gave Thanks to ctsgnb For This Post:
# 7  
Old 11-17-2010
I got the outputs.
Code:
[hsar@catom-gmapdvl05 ~]$ cat output.ok
Param                                                                 9i                                             11g
db_block_size                                                       8192                                            8192
db_cache_size                                                      1024M                                           1024M
db_file_multiblock_read_count                                         32                                              32
open_cursors                                                        1000                                            1000
diagnostic_dest                                                      ---                                /u01/app/oracle/
db_unique_name                                                       ---                                           dcicr
[hsar@catom-gmapdvl05 ~]$ cat output.all
Param                                                                 9i                                             11g
db_block_size                                                       8192                                            8192
db_cache_size                                                      1024M                                           1024M
db_file_multiblock_read_count                                         32                                              32
open_cursors                                                        1000                                            1000
cursor_sharing                                                       ---                                         SIMILAR
background_dump_dest                  /usr/local/oracle/admin/dcap/bdump                                             ---
core_dump_dest                        /usr/local/oracle/admin/dcap/cdump                                             ---
user_dump_dest                        /usr/local/oracle/admin/dcap/udump                                             ---
diagnostic_dest                                                      ---                                /u01/app/oracle/
db_unique_name                                                       ---                                           dcicr
memory_max_target                                                    ---                                             ---
memory_target                                                        ---                                             ---
pga_aggregate_target                                                512M                                            512M
java_pool_size                                                      150M                                            150M
large_pool_size                                                      50M                                             64M
shared_pool_size                                               268435456                                            512M
[hsar@catom-gmapdvl05 ~]$ cat output.err
Param                                                                 9i                                             11g
Warning : cursor_sharing does not have the same values in 9i.ora and 11g.ora : missmatch !
cursor_sharing                                                       ---                                         SIMILAR
Warning : background_dump_dest does not have the same values in 9i.ora and 11g.ora : missmatch !
background_dump_dest                  /usr/local/oracle/admin/dcap/bdump                                             ---
Warning : core_dump_dest does not have the same values in 9i.ora and 11g.ora : missmatch !
core_dump_dest                        /usr/local/oracle/admin/dcap/cdump                                             ---
Warning : user_dump_dest does not have the same values in 9i.ora and 11g.ora : missmatch !
user_dump_dest                        /usr/local/oracle/admin/dcap/udump                                             ---
Warning : memory_max_target is missing in file 11g.ora
memory_max_target                                                    ---                                             ---
Warning : memory_target is missing in file 11g.ora
memory_target                                                        ---                                             ---
Warning : pga_aggregate_target should not be in file 11g.ora
pga_aggregate_target                                                512M                                            512M
Warning : java_pool_size should not be in file 11g.ora
java_pool_size                                                      150M                                            150M
Warning : large_pool_size should not be in file 11g.ora
large_pool_size                                                      50M                                             64M
Warning : shared_pool_size should not be in file 11g.ora
shared_pool_size                                               268435456                                            512M
[hsar@catom-gmapdvl05 ~]$

Thanks you very very much

---------- Post updated at 08:08 AM ---------- Previous update was at 06:00 AM ----------

Hi,
for first condition it is working properly.Now i have included parameters needs to check for second and third condition in listparam file but now it's not giving the second and third outputs.
These are the parameters i have included in my paramlist file:
diagnostic_dest 2
db_unique_name 2
memory_max_target 2
memory_target 2

pga_aggregate_target 3
java_pool_size 3
large_pool_size 3
shared_pool_size 3
shared_pool_reserved_size 3
db_keep_cache_size 3
db_recycle_cache_size 3
sga_target 3.
The output i got is:
it is only checking for first condition:

Param 9i 11g
Warning : cursor_sharing does not have the same values in 9i.ora and 11g.ora : missmatch !
cursor_sharing --- SIMILAR
Warning : background_dump_dest does not have the same values in 9i.ora and 11g.ora : missmatch !
background_dump_dest /usr/local/oracle/admin/dcap/bdump ---
Warning : core_dump_dest does not have the same values in 9i.ora and 11g.ora : missmatch !
core_dump_dest /usr/local/oracle/admin/dcap/cdump ---
Warning : user_dump_dest does not have the same values in 9i.ora and 11g.ora : missmatch !
user_dump_dest /usr/local/oracle/admin/dcap/udump ---
Warning : log_archive_dest does not have the same values in 9i.ora and 11g.ora : missmatch !
log_archive_dest /archive/dcap/arch/ use_db_recovery_file_dest'
Warning : log_archive_start does not have the same values in 9i.ora and 11g.ora : missmatch !
log_archive_start TRUE ---
Warning : log_archive_format does not have the same values in 9i.ora and 11g.ora : missmatch !
log_archive_format dcap%t_%s.arc ---
Warning : service_names does not have the same values in 9i.ora and 11g.ora : missmatch !
service_names dcap dcicr,dcicr.world
Warning : control_files does not have the same values in 9i.ora and 11g.ora : missmatch !
control_files ( "/u02/oradata/dcap/control01.ctl",
(+DCI/dcicr/controlfile/current.256.725043389,
Warning : compatible does not have the same values in 9i.ora and 11g.ora : missmatch !
compatible 9.2.0 11.1.0
Warning : db_name does not have the same values in 9i.ora and 11g.ora : missmatch !
db_name dcap dcicr
Warning : instance_name does not have the same values in 9i.ora and 11g.ora : missmatch !
instance_name dcap dcicr1
Warning : processes does not have the same values in 9i.ora and 11g.ora : missmatch !
processes 500 4
10 1000 2
Warning : job_queue_processes does not have the same values in 9i.ora and 11g.ora : missmatch !
job_queue_processes 4 2
Warning : log_buffer does not have the same values in 9i.ora and 11g.ora : missmatch !
log_buffer 524288 10485760
Warning : undo_tablespace does not have the same values in 9i.ora and 11g.ora : missmatch !
undo_tablespace undots undots1
Warning : undo_retention does not have the same values in 9i.ora and 11g.ora : missmatch !
undo_retention 6000 #
added 4/17 to
correct snapshot too
old - RG
3600
Warning : audit_trail does not have the same values in 9i.ora and 11g.ora : missmatch !
audit_trail DB OS
Warning : sql92_security does not have the same values in 9i.ora and 11g.ora : missmatch !
sql92_security TRUE TRUE
Warning : audit_file_dest does not have the same values in 9i.ora and 11g.ora : missmatch !
audit_file_dest --- /u01/app/oracle/admin/dcicr/audit
Warning : O7_dictionary_accessibility does not have the same values in 9i.ora and 11g.ora : missmatch !
O7_dictionary_accessibility --- FALS

Last edited by vbe; 11-17-2010 at 09:35 AM.. Reason: code tags!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell Script to Compare Files and Email the differences

Hi, I have 2 files abc.txt and bdc.txt. I am using $diff -y abc.txt bcd.txt -- compared the files side by side I would like to write a Shell Script to cmpare the files side by side and print the results( which are not matched) in a side by side format and save the results in another... (10 Replies)
Discussion started by: vasuvv
10 Replies

2. Shell Programming and Scripting

Shell script to compare two files for duplicate..??

Hi , I had a requirement to compare two files whether the two files are same or different .... like(files contaisn of two columns each) file1.txt 121343432213 1234 64564564646 2345 343423424234 2456 file2.txt 121343432213 1234 64564564646 2345 31231313123 3455 how to... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

3. Shell Programming and Scripting

Using shell script to compare files and retrieve connections

Hello, I want to use shell script to generate network files (I tried with python but its taking too long). I have a list of nodes: node.txt LOC_Os11g37970 LOC_Os01g07760 LOC_Os03g19480 LOC_Os11g45740 LOC_Os06g08290 LOC_Os07g02800 I have an edge-list as well: edge.txt Source_node ... (2 Replies)
Discussion started by: Sanchari
2 Replies

4. Shell Programming and Scripting

How to use awk shell script to compare and match two files?

Basically, I have two files dupestest.txt 152,153 192,193,194 215,216 290,291 2279,2280 2282,2283haftest.txt 152,ABBOTS ROAD 153,ABBOTS ROAD 154,ABBOTS ROAD 155,ABBOTS ROAD 156,ABBOTS ROAD 157,ABBOTS ROADI want to find the numbers in dupestest.txt in haftest.txt... (4 Replies)
Discussion started by: amyc92
4 Replies

5. Shell Programming and Scripting

Compare two files using shell script

Hi i want to compare two files and i need the o/p of only difference here the files file1 achilles aedxbepo aedxbwdm01 aedxbwdm02 albedo amarice ambrister anakin anton argon artephius asgard avatar aymara (10 Replies)
Discussion started by: venikathir
10 Replies

6. Shell Programming and Scripting

Shell script to compare two files

I have two files; file A and file B. I need all the entries of file A to be compared with file B line by line. If the entry exists on file B, then save those on file C; if no then save it on file D Note :- all the columns of the lines of file A need to be compared, except the last two columns... (8 Replies)
Discussion started by: ajiwww
8 Replies

7. Shell Programming and Scripting

How to write a shell script to display files in single path?

Hello friends, I am a script which dispalys a multiple files with their contents. for exm: suppose two file test1.txt and test2.txt. when I run my script it have to display the below O/P. test1.txt -rw-r----- 1 sranga staff 91 Sep 23 02:18 calc.sh -rw-r----- 1 sranga ... (2 Replies)
Discussion started by: sivaranga001
2 Replies

8. Shell Programming and Scripting

Shell Script to Compare Two Files

I have a directory with about 6 files that we receive regularly. these 6 files contain information for 3 different units, 2 for each unit. files related to a specific unit are named similarly with a change in number at the end of the file. the numbers should be sequential. for each grouping of... (3 Replies)
Discussion started by: scriptman237
3 Replies

9. UNIX for Dummies Questions & Answers

Create a shell script for write files with 2 parameters

Hello, I'm a newbie in shell script. So, i would like to create a shell script which take 2 IN parameters (PARAM1 and PARAM2). This script need to create 2 files as : I need to create this file /etc/apache2/sites-available/PARAM2 : <VirtualHost *:80> DocumentRoot "/home/PARAM1/www"... (0 Replies)
Discussion started by: chatlumo
0 Replies

10. UNIX and Linux Applications

How to compare two files using shell script

hi experts please help me to compare two files which are in different directory file1<file will be master file> (/home/rev/mas.txt} ex x1 x2 file2 <will be in different folder> (/home/rev/per/.....) ex x3 x4 the filesinside per folder i need to compare with master file... (1 Reply)
Discussion started by: revenna
1 Replies
Login or Register to Ask a Question