Home » Linux » Gathering and aggregating system information in Linux

Gathering and aggregating system information in Linux

Last updated May 17, 2021

In this article, we are going to discuss the dmidecode Linux tool, which will gather information about the system such as CPU information, server, memory, and networking.

Prerequisites

Besides having a terminal open, we need to remember a few concepts:

  • We are going to use some commands that will give us information about the Kernel, Linux distribution, physical server information, system uptime, network information, memory information, and CPU information.
  • By using this, anyone can create scripts to gather system information.

How to do it

We can get details about the Linux distribution that you are working on. These distributions have a release file that you can locate in the /etc/ folder. Now, open a terminal and enter the following command to get the information regarding the Linux distribution you are working on:

cat /etc/*-release

The preceding option has an alternative, and the alternative is the version file that’s present in the /proc folder. So, run the following command:

cat /proc/version

Now, run the following command to get the Kernel’s information:

uname -a

System uptime: for information about this, create a script called server_uptime.sh:

server_uptime=`uptime | awk '{print $3,$4}'| sed 's/,//'| grep "day"`; 
if [[ -z "$server_uptime" ]]; then 
	server_uptime=`uptime | awk '{print $3}'| sed 's/,//'` 
	echo $server_uptime 
else 
	:; 
fi;

Now, we will run the following commands to get the physical server’s information:

$ sudo dmidecode -s system-manufacture 
$ sudo dmidecode -s system-product-name 
$ sudo dmidecode -s system-serial-number

Then, we will run the following command to get the CPU’s information:

sudo dmidecode -t4|awk '/Handle / {print $2}' |sed 's/,//'

You can get each CPU’s information from the cpuinfo file, which is present in the /proc directory.

Network information: We are going to get the IP address by running the following command:

ip a

To get the MAC address, run the following command:

ip addr show ens33

You may replace ens33 with eth0, depending on your network interface’s information.

Memory information: To get the total number of slots, run the following command:

sudo dmidecode -t17 |awk '/Handle / {print $2}'|wc -l

To get the total populated slots, run the following command:

sudo dmidecode -t17 |awk '/Size:/'|awk '!/No/'|wc -l

To get the total unpopulated slots, run the following command:

sudo dmidecode -t17 |awk '/Size:/'|awk '/No/'|wc -l

How it works

After running the cat /etc/*-release command, press Enter and you will get the output according to your Linux distribution. In my case, the output is as follows:

DISTRIB_ID=Ubuntu 
DISTRIB_RELEASE=16.04 
DISTRIB_CODENAME=xenial 
DISTRIB_DESCRIPTION="Ubuntu 16.04.4 LTS" 
NAME="Ubuntu" 
VERSION="16.04.4 LTS (Xenial Xerus)" 
ID=ubuntu 
ID_LIKE=Debian 
PRETTY_NAME="Ubuntu 16.04.4 LTS" 
VERSION_ID="16.04" 
HOME_URL="http://www.ubuntu.com/" 
SUPPORT_URL="http://help.ubuntu.com/" 
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" 
VERSION_CODENAME=xenial 
UBUNTU_CODENAME=xenial

There is an alternate way to get system information. You can get the system information by running a version file from the /proc directory. After running the command, press Enter, and you will get the output according to your Linux distribution. In my case, the output is as follows:

Linux version 4.13.0-45-generic (buildd@lgw01-amd64-011) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9)) #50~16.04.1-Ubuntu SMP Wed May 30 11:18:27 UTC 2018

uname is the tool that we are using to gather this information. Press Enter after running the command and you will get the Kernel information. In my case, the output is as follows:

Linux ubuntu 4.13.0-45-generic #50~16.04.1-Ubuntu SMP Wed May 30 11:18:27 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Execute the $ bash server_uptime.sh script—press Enter at the prompt and you will get the uptime of the server.

To get the physical server information, we used the dmidecode tool. The first command is used to get the manufacturer’s information, the second command is to get the model name, and the third command gets the serial number. While running a dmidecode command, you must be the root user.

The output snippet will look as follows:

0x0004 
0x0005 
0x0006 
0x0007

To get each CPU’s information, we created a script. Execute the $ sudo bash cpu_info.sh script—press Enter at the prompt and you will get information for each CPU.

The output snippet will look like the following:

CPU#000 
Unknown 
GenuineIntel 
1800MHz 
3.3V 
1 
CPU#001 
Unknown 
GenuineIntel 
1800MHz 
3.3V 
1 
CPU#002 
Unknown 
GenuineIntel 
1800MHz 
3.3V 
1 
CPU#003 
Unknown 
GenuineIntel 
1800MHz 
3.3V 
1

Network information: We ran the ip command to get the IP address and MAC address.

Memory information: We used the dmidecode tool to get the memory information such as the total number of slots, and the total populated and unpopulated slots. You must be the root user to run this command.

Related Posts

Creating a lame utility HTTP server in Linux Operating System

In this article, we will discuss the cURL tool in Linux. The cURL tool is used for transferring the data from or to a server. It supports many protocols, and http is one of them. cURL is used to transfer the data from URL. It has so many tricks to offer, such as http...

Finding binary dependencies in Linux Operating System

In this article, we are going to check the executable. We will find out which string is present in it by using the string command.PrerequisitesBesides having a terminal open, make sure you have a binary present in your directory.Find dependencies First, we...

Capturing network traffic headlessly in Linux Operating System

In this article, we are going to learn how to capture traffic. We are going to capture network traffic with a packet sniffer tool called tcpdump. This tool is used to filter or capture TCP/IP packets that are transferred or received over a network.PrerequisitesBesides...

0 Comments

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

six + 5 =

Follow Us

Our Communities

More on Linux

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!