In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
The use of Linux shell tool grep awk cut sort uniq sort analysis, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
In Linux system, there are many tools for dealing with data quickly, such as grep awk cut sort uniq sort, which are very easy to use. If you are proficient in their skills, they can help you identify problems quickly.
I came across a case recently. A database system on a project, ORACLE, runs on LINUX and reports that the number of processes is full. When you see this kind of problem, you don't need to dig into the warning log, the state of the process in the database, and so on. Immediately see which servers are connected to this database server at the operating system level.
The first tool used here is netstat. He is a system management tool, not a shell tool.
Through netstat-ntu, find the list of IP addresses that connect to the server through tcp and udp.
Omit below, too much to show all.
This is a list of all external IP information connected to the database server.
You can see that the fifth column contains all the external IP information. Based on this information, find out the number. What is the IP? Or make a sort based on the number of IP.
The first step is to filter out the tcp using grep, or you can use egrep to filter multiple conditions
Netstat-ntu | grep 'tcp'
Netstat-ntu | egrep 'tcp | udp'
The second step is to use awk to separate the fifth column.
Netstat-ntu | grep 'tcp' | awk' {print $5}'
Do the following:
The third step is to use cut to divide the column information into different columns with ":" as the delimiter to display the first field
Netstat-ntu | grep 'tcp' | awk' {print $5}'| cut-d:-F1
Step 4, sort the field values using the sort default character order
Netstat-ntu | grep 'tcp' | awk' {print $5}'| cut-d:-F1 | sort
There are many options for sort, which can be seen by man sort.
Step five, use uniq to calculate the number of different values for the sorted fields.
Netstat-ntu | grep 'tcp' | awk' {print $5}'| cut-d:-F1 | sort | uniq-c
Uniq-c calculates the sum based on similar values, so it needs to be sorted before.
Step 6, use sort-n digital ascending order to sort the results again.
Netstat-ntu | grep 'tcp' | awk' {print $5}'| cut-d:-F1 | sort | uniq-c | sort-n
With sort-nr, you can sort them in descending numerical order.
Netstat-ntu | grep 'tcp' | awk' {print $5}'| cut-d:-F1 | sort | uniq-c | sort-nr
Step 7, use head or tail to fetch lines from the head or tail
Fetch 10 lines from the tail
Netstat-ntu | grep 'tcp' | awk' {print $5}'| cut-d:-F1 | sort | uniq-c | sort-n | tail-10
Take 10 lines from the head
Netstat-ntu | grep 'tcp' | awk' {print $5}'| cut-d:-F1 | sort | uniq-c | sort-nr | head-10
This gives us the result we want.
In this result, we can see the number of network connections on each server on the database server.
According to the number of connections, found that very large, there must be a problem. Usually, the application server opens the connection and does not close it, or it cannot be closed when an exception occurs.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.