Sunday, April 17, 2016

UNIX Server hardware inventory

Unix systems offer many commands that can be used to pull information from your servers and help you prepare an inventory of your systems. Putting these commands into a script can be especially handy if you are managing hundreds of servers. Depending on your setup, you can run these commands remotely and collect the results in a central repository or you can run them on each server and have the results sent back to a specified location.

Some of the most useful information you will likely want to collect if you are maintaining a profile of each of the servers you manage includes:

the server name
its IP address
the number of CPUs and cores
the processor speed
your disk sizes
what OS is in use
the amount of memory on the system
the manufacturer
the server model
uptime
If you're running critical applications, you might want to collect some information on those as well. In the example systems shown below, we're also going to collect some data on the Oracle services that are running.

The basic script looks like this. In this script, we're using uname and ifconfig to get the server name and IP address and we're pulling information on the number of CPUs and cores plus the CPU speed from two of the files in the /proc file system. I've also added a check for a particular file on RedHat systems that will display the OS name to augment the build information that uname provides. Another file in /proc provides a display of how much memory the server has installed.

The script also includes a couple lshal commands to query the hardware.

getSysInfo

#!/bin/bash

echo -n "Name: "
uname -n
echo -n "IP: "
ifconfig | grep "inet addr" | grep -v 127.0.0.1 | awk '{print $2}' | awk -F: '{print $2}'
echo -n "CPUs: "
grep "physical id" /proc/cpuinfo | sort | uniq | wc -l
echo -n "Cores: "
grep "^processor" /proc/cpuinfo | wc -l
echo -n "Processor speed (MHz): "
grep MHz /proc/cpuinfo | sort | awk '{print $NF}' | uniq -c
echo -n "Disk(s): "
fdisk -l | grep Disk
echo -n "OS: "
uname -o -r
if [ -f /etc/redhat-release ]; then
    echo -n "  "
    cat /etc/redhat-release
fi
echo -n "Memory: "
grep MemTotal /proc/meminfo | awk '{print $2,$3}'
echo -n "Up for: "
uptime | awk '{print $3,$4,$5}'
echo -n "Manufacturer: "
lshal | grep system\.hardware | grep "vendor" | grep -v video | awk -F\' '{print $2}'
echo -n "Model: "
lshal | grep system\.hardware | grep "product" | grep -v video | awk -F\' '{print $2}'

The output from this script will look something like this. Notice that there's an extra line in the processor speed section. On this particular system, one of the four CPUs is running at a different speed than the other three.

$ ./getSysInfo
Name: vader.aacc.edu
IP: 192.168.0.6
CPUs: 2
Cores: 4
Processor speed (MHz):       1 2800.000
      3 3400.000
Disk(s): OS: 2.6.18-371.3.1.el5 GNU/Linux
  Red Hat Enterprise Linux Server release 5.10 (Tikanga)
Memory: 2074932 kB
Up for: 115 days, 4:28,
Manufacturer: HP
Model: ProLiant DL380 G4
Adding some Oracle queries


No comments:

Post a Comment