Unix: Automating your server inventory

By  

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.

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Answers - Powered by ITworld

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Ask a Question