Find out how to gather all the configuration and diagnostic information you need about a Linux server with a single command.
We all love data. It’s almost as though IT couldn’t function without it. So much so, we go to great lengths to collect data about our systems, services, clients, and much more. But what about those Linux servers in your data center? What do you do when it comes time to collect data about those systems?
You could turn to the sosreport tool. Sosreport is a single command that does an outstanding job of collecting configuration details and diagnostic information for your Linux servers.
I want to get you up to speed on the sosreport tool. I’ll be demonstrating on Ubuntu Server 18.04.
SEE: Hiring kit: Database administrator (TechRepublic Premium)
What you’ll need
- A running instance of Ubuntu Server 18.04
- A user account with sudo privileges
How to install sosreport
Sosreport should already be installed on your distribution. On the off-chance it isn’t, here’s how to add it:
- Open a terminal window.
- Issue the command sudo apt-get install sosreport -y.
- When prompted, type your sudo password.
- Allow the installation to complete.
That’s it, sosreport is now installed and ready to be used. You might also want to install the tree command (for easier viewing of the reports) with the command:
sudo apt-get install tree -y
How to use sosreport
The basic usage of sosreport is the command:
You will be prompted to hit Enter to continue and then enter an option case ID (Figure A).
This will take a few seconds or up to a minute or two, depending on the complexity of your server, to gather all the information about your system. The finished report will be a compressed tar file in /tmp (the exact name of the report will be listed when the command completes).
To view the contents of that report, you’ll want to move the file, change the ownership of the file, and uncompress it. Do that with the following commands:
- Move the file with the command sudo mv /tmp/FILENAME.tar.xz ~/ (where FILENAME is the exact name of the file).
- Change the ownership of the file with the command sudo chown $USER.$USER FILENAME.tar.xz (where FILENAME is the exact name of the file).
- Uncompress the file with the command tar xvf FILENAME.tar.xz.
The final command above will create a new directory. Change into that directory with the command cd FILENAME (where FILENAME is the name of the newly-created directory). In this new directory, you’ll see a number of sub-directories and files (Figure B).
That’s a lot of information to consume. Let’s narrow it down a bit.
Per plugin information
One important feature of sosreport is that it allows you to see what plugins options are available. From that list, you can opt to enable or disable any plugin you need or only view information about a specific service. To find out what plugins are enabled and disabled, issue the command:
sudo sosreport -l
This will list out everything enabled and disabled (Figure C).
Let’s say you see that the Apache plugin is available, but not enabled. To enable that plugin, you’d issue the command:
sudo sosreport --enable-plugins apache
Now, say you only want to generate a report for the Apache plugin. Do this with the command:
sudo sosreport -o apache --batch
Now, let’s view that report with the following commands:
- Unpack the file with the command sudo tar xvf /tmp/FILENAME.tar.xz (where FILENAME is the name of the file).
- Change to the root user with the command sudo -s.
- Change into the newly created directory with the command cd /tmp/FILENAME (where FILENAME is the name of the newly created directory).
- View the hierarchy of the files with the command tree.
From the output of the tree command (Figure C), you can see the hierarchy of the report directory.
From that view, you can decide which file to view, or send the .tar.xz file to someone who can comb through the data to troubleshoot an issue.
Why use this tool?
After viewing the output of the command, you might be asking yourself, “Why use this tool?” After all, you can simply use the terminal window to gather this information, bit by bit. Right? Of course you can. But what if you need to send a collection of information about a system to a vendor or a higher-level administrator? When that’s the case, you certainly don’t want to have to gather that information one file at a time. Instead, you can now use sosreport to collect all the necessary data together in a single packaged file and send it off for analysis. That’s considerably more efficient than gathering the data manually. And when you’re dealing with a data center worth of servers, efficiency is the name of the game.