Compare tables record count from 2 different databases via shellscript
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Compare tables record count from 2 different databases via shellscript
Hi,
I want to compare the records count of around 200 tables from db1 with record count of same 200 tables from db2 thro she'll script, please let me know how we can do it in a simplified way using shellscript as we are planning to schedule this , any code snippet on this is really helpful. Since there ar 200 tables , we need to reduce the time as much as possible as well. Please provide your input with code snippet/ examples which will surely help us in this case.
Yes, some of your code would help. Please show what you have started with and explain your approach so that we may provide advice. Also show some sample records from each table or explain how they are stored. Are they flat, tab separated values? Or are they in some kind of SQL database? We'll help you but not do your work for you, besides some of our hourly rates would scare you.
Please realize that forum members are here as volunteers and the way LQ works is that these volunteers are here to help you as you attempt to solve your own problem.
Therefore it is prudent that you show what you have tried and where you are stuck. People will certainly be willing to offer suggestions and improvements to you work, but people are not here to write your scripts for you.
This looks like a very standard requirement for instance to test the integrity of a data base copy that first you should look for an existing solution in the help fora of your data base.
Still, if you want to do it in a shell script,
First
Is the list of "around 200 tables" fixed (so you can put it into a list or is is to be taken from the data dictionary by something like select tablename from iitables.. . Append the result to a 3 column array with the table name in the first column.
Next open (prepare .. whatever) the 2 data bases.
Cycle the array by index.
col2[index]=select count * from col1[index] from the first data base
col3[index]=select count * from col1[index] from the second data base
If the result differs, print the error message
Loop
Clearly this is just an idea without knowing about your database, resources etc.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.