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.
- TEST1 100
- TEST2 450
- TEST3 300
- TEST4 150
Simulate this problem.
Use the following script a. sh to generate the DUMP file.
- for i in {1..$2}
- do
- touch $1_EXT_$i.dmp
- done
Generate the 1000 dump files.
- [ora11g@rac1 DUMP]$ ksh a.sh TEST1 100
- [ora11g@rac1 DUMP]$ ksh a.sh TEST2 450
- [ora11g@rac1 DUMP]$ ksh a.sh TEST3 300
- [ora11g@rac1 DUMP]$ ksh a.sh TEST4 150
- [ora11g@rac1 DUMP]$ ll *.dmp|wc -l
- 1000
Let's take a look at the dump generated.
- [ora11g@rac1 DUMP]$ ll *.dmp|tail -10
- -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_91.dmp
- -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_92.dmp
- -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_93.dmp
- -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_94.dmp
- -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_95.dmp
- -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_96.dmp
- -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_97.dmp
- -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_98.dmp
- -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_99.dmp
- -rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_9.dmp
- [ora11g@rac1 DUMP]$
First, we need to obtain several related tables in this directory.
For example, in the current situation, you need to obtain
- TEST1
- TEST2
- TEST3
- TEST4
You can use the following command for statistics.
- [ora11g@rac1 DUMP]$ ls -lrt *.dmp|awk '{print $9}'|awk -F_EXT '{print $1}'|uniq
- TEST1
- TEST2
- TEST3
- 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
- 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
- ksh test.sh
- rm test.sh
- [ora11g@rac1 DUMP]$ ksh b.sh
- [ora11g@rac1 DUMP]$ cat tablst
- TEST1 100
- TEST2 450
- TEST3 300
- TEST4 150
In this way, the statistics of files are clear and clear.