Linux : Easily get any system details


Background

Sometimes, when writing scripts or when troubleshooting a problem on a Linux platform you are struggling to remember how to get the number of cores, the current IP address, the kernel version, available space, ... All those settings are present somewhere in the system. Remember, with Linux, everything is file based. There is a way to easily get those details with one single command. Please continue reading !

Let's meet "facter"

Funny enough, I'm in the Linux business for the last 20 years and I just discovered yesterday the command facter ! We are learning everyday right ? But I don't know how I can pass over this for so long. Amazing & powerful it gives you immediate access to so many variables that I cannot name them all here. Here is a sample of the facter output on my test system :

# facter
architecture => x86_64
bios_release_date => 04/01/2014
bios_vendor => SeaBIOS
bios_version => 1.9.1-5.el6
blockdevice_sda_model => VDISK
blockdevice_sda_size => 32212254720
blockdevice_sda_vendor => NUTANIX
blockdevice_sdb_model => VDISK
blockdevice_sdb_size => 107374182400
blockdevice_sdb_vendor => NUTANIX
blockdevice_sr0_model => QEMU DVD-ROM
blockdevice_sr0_size => 1073741312
blockdevice_sr0_vendor => QEMU
blockdevices => sda,sdb,sr0
dhcp_servers => {"system"=>"192.168.8.254", "eth0"=>"192.168.8.254"}
facterversion => 2.4.1
filesystems => xfs
fqdn => facter
gid => root
hardwareisa => x86_64
hardwaremodel => x86_64
hostname => facter
id => root
interfaces => eth0,lo
ipaddress => 192.168.8.115

There a lot more than just the above, actually there are 88 variables on my platform that can be used for anything.

You can use the command by simply pointing out the relevant parameter. As matter of example, getting the ip address of the machine by simply entering :

# facter ipaddress
192.168.8.115

I really encourage you to use it in your scripts. Initially this script has been created for puppet and is now available standalone. This is not default on Linux platform you need to install it via the EPEL repository.

Install facter

Facter is available via the EPEL repository, so, first, you need to add EPEL to your system.

# rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.standaloneinstaller.com
 * epel: mirror.23media.de
 * extras: mirrors.standaloneinstaller.com
 * updates: mirror.plusserver.com
repo id            repo name                            status
base/7/x86_64      CentOS-7 - Base                      9,911
epel/x86_64        Extra Packages for Enterprise Linux 7 - x86_64                                                               12,577
extras/7/x86_64    CentOS-7 - Extras                    305
updates/7/x86_64   CentOS-7 - Updates                   632
repolist: 23,425


Repolist above confirms your EPEL repo has been added and enabled into your system.

Now, just install facter as usual with yum :

# yum install facter -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.standaloneinstaller.com
 * epel: mirror.23media.de
 * extras: mirrors.standaloneinstaller.com
 * updates: mirror.plusserver.com
Resolving Dependencies
--> Running transaction check
---> Package facter.x86_64 0:2.4.1-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================
 Package                     Arch                        Version                            Repository                 Size
============================================================================================================================
Installing:
 facter                      x86_64                      2.4.1-1.el7                        epel                      101 k

Transaction Summary
============================================================================================================================
Install  1 Package

Total download size: 101 k
Installed size: 271 k
Downloading packages:
facter-2.4.1-1.el7.x86_64.rpm                                                                        | 101 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : facter-2.4.1-1.el7.x86_64                                                                                1/1 
  Verifying  : facter-2.4.1-1.el7.x86_64                                                                                1/1 

Installed:
  facter.x86_64 0:2.4.1-1.el7                                                                                               

Complete!

Enjoy !

Comments

What's hot ?

Raspberry Pi : WiFi Hotspot for the Garden!

ShredOS : HDD degaussing with style

Wallbox : Get The Most Of It (with API)