Use shell scripts to skillfully collect statistics files

Source: Internet
Author: User

Use shell scripts to skillfully collect statistics files

During data migration, a large number of dump files are generated. You need to perform a simple and clear management of dump files. For example, there are many files in the directory, in addition, some tables are relatively large and correspond to a large number of dump files. In this case, we want to get a very concise report and calculate the number of dump files in each table.

For example, there are 1000 dump files, all of which are based on tables TEST1, TEST2, TEST3, and TEST4. So I want to get a simple statistical report, similar to the following form.

 
 
  1. TEST1 100  
  2. TEST2 450  
  3. TEST3 300  
  4. TEST4 150 

Simulate this problem.

Use the following script a. sh to generate the DUMP file.

 
 
  1. for i in {1..$2}  
  2. do  
  3. touch $1_EXT_$i.dmp  
  4. done 

Generate the 1000 dump files.

 
 
  1. [ora11g@rac1 DUMP]$ ksh a.sh TEST1 100  
  2. [ora11g@rac1 DUMP]$ ksh a.sh TEST2 450  
  3. [ora11g@rac1 DUMP]$ ksh a.sh TEST3 300  
  4. [ora11g@rac1 DUMP]$ ksh a.sh TEST4 150  
  5. [ora11g@rac1 DUMP]$ ll *.dmp|wc -l  
  6. 1000 

Let's take a look at the dump generated.

 
 
  1. [ora11g@rac1 DUMP]$ ll *.dmp|tail -10  
  2. -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_91.dmp  
  3. -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_92.dmp  
  4. -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_93.dmp  
  5. -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_94.dmp  
  6. -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_95.dmp  
  7. -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_96.dmp  
  8. -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_97.dmp  
  9. -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_98.dmp  
  10. -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_99.dmp  
  11. -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_9.dmp  
  12. [ora11g@rac1 DUMP]$ 

First, we need to obtain several related tables in this directory.

For example, in the current situation, you need to obtain

 
 
  1. TEST1  
  2. TEST2  
  3. TEST3  
  4. TEST4 

You can use the following command for statistics.

 
 
  1. [ora11g@rac1 DUMP]$ ls -lrt *.dmp|awk '{print $9}'|awk -F_EXT '{print $1}'|uniq  
  2. TEST1  
  3. TEST2  
  4. TEST3  
  5. TEST4 

Next, let's take a closer look at how many dump files correspond to each table.

You can use the following script B. sh to quickly obtain

 
 
  1. ls -lrt *.dmp|awk '{print $9}'|awk -F_EXT '{print $1}'|uniq|xargs -i echo "echo {} \`ls -lrt {}_EXT_[0-9]*.dmp|wc -l \`>> tablst" >test.sh  
  2. ksh test.sh  
  3. rm test.sh  
  4. [ora11g@rac1 DUMP]$ ksh b.sh  
  5. [ora11g@rac1 DUMP]$ cat tablst  
  6. TEST1 100  
  7. TEST2 450  
  8. TEST3 300  
  9. TEST4 150 

In this way, the statistics of files are clear and clear.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.