tail -f findings.out

Convenient OS and hardware summary information

There are quite a number of ways to get information on your OS and especially your hardware on a Linux system. Instead of remembering them all and sorting through their output, I put together a pair of functions that provide useful summary information at a glance. While the more detailed tools are indispensable when you need, well, more detailed information, these might fit the bill most often when you just need to find out what sort of system you are dealing with.

OS and Kernel

This function doesn’t show a lot of information, but for me it makes things more intuitive. It took a while before uname came naturally. So I created:

1
2
3
4
5
6
7
function os {
    export OPER_SYS_1="`uname -s`"
    export OPER_SYS_2="`cat /etc/issue | head -n 1`"
    export KERN_INFO="`uname -r`"
    echo -ne "\033[31mOS:\033[0m " && echo "$OPER_SYS_1, $OPER_SYS_2"
    echo -e "\033[32mKernel:\033[0m $KERN_INFO"
}

Which will give you something like:

Hardware

While there is an obscene amount of information you can gather from Linux about your machine’s hardware, you often don’t necessarily care about most of it. Most often you probably just need basic stats such as total RAM, CPU speed and HDD space. This function will give you that in a compact display. I also threw in some motherboard information because I often need to check the manual for a board online and don’t want to have to open the case just to get the model:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function hw () {
    export MOBO_MAN="`sudo dmidecode --type baseboard | grep 'Manufacturer' | cut -d' ' -f2-`"
    export MOBO_MOD="`sudo dmidecode --type baseboard | grep 'Product' | cut -d' ' -f3-`"
    export CPU="`cat /proc/cpuinfo | grep 'model name' | cut -d' ' -f3-`"
    export RAM_TOTAL_KB="`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`"
    export HDD_INFO="`sudo fdisk -l | grep Disk | grep -v identifier`"
    echo -e "\033[1;34mHardware\033[0m:"
    echo " * Motherboard:"
    echo "   * Manufacturer: $MOBO_MAN"
    echo "   * Model: $MOBO_MOD"
    echo " * CPU(s):"
    echo "$CPU"
    echo " * Total RAM: $(($RAM_TOTAL_KB / 1024)) MB"
    echo " * HDD info: "
    echo "$HDD_INFO"
    echo
}

The result:

Putting them together

I find I most often want to see information on the OS and hardware together. To achieve that, just create a simple alias such as:

1
alias system="os && hw"

Then simply running “system” will show you basic information about the system you are on. Pretty intuitive!

Notes

  • I made use of the DMI via dmidecode to provide some of the hardware information. Although I have never had any problems with it, it is possible for this information to be inaccurate. From everything I have read, it seems to be reliable on all common Linux systems and platforms.
  • If you run this on, say, a virtual private server (pretty common as a hosting solution), you will likely not have permission to get some of the hardware info, even running it with sudo, simply because of how your VPS is setup. Not much you can do about that, but the commands will still show you what output they can.
Tags: , , , ,
January 3, 2009 - 8:13 PM No Comments

Show processes as a tree

The

1
<a href="http://www.bellevuelinux.org/pstree.html">pstree command</a>

shows the ancestral relationships between processes running on a machine. What does that mean? It means you can see an awesome tree of what’s running on your box, instead of the boring output of ps. Check it:

It compresses multiple descendants into a single entry, with the number of descendents (like for apache2 and mysqld here). You can also have it search by user, pid, and more. See the man page for exact details.

Other nice features are being able to highlight certain processes and show command line arguments. So if you wanted to see how the latest apache2 process was called, you could run

pgrep -n apache2 | xargs -I mystr pstree -apH mystr

and get back:

This isn’t a particularly interesting example, but if you knew one of a number of scripts might be causing MySQL to act up, for instance, you could call their names in the pgrep search, and quickly see who called it.

Tags: , , ,
November 3, 2008 - 2:08 AM No Comments

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.