Sunday, October 17, 2010

How to get the system information from bash command prompt

Process info
: top

  • Then A ([{shift} + A) to have multi-window process view. Do again to go back to normal view
  • Type k and input process ID (PID) to kill a process
  • Type u and input user name to get process from the user alone


Process information
: ps -Af
: ps -u username -Af


Check the free RAM available
: free -m

Hard disk and mounted file systems
: fdisk -l (as root)
: df -hT
: cat  /etc/fstab
: du -h --max-depth=1


Other Hardware info
: uname -a
: cat /proc/cpuinfo
: cat /proc/version

/proc directory contain several info
use cat to read the files in /proc such as

cpuinfo,
devices,
filesystems,
meminfo,
partitions,
swaps,
uptime,
version

: cat /proc/cpuinfo
: cat /proc/version

: dmesg | head -2

: lspci   
(as root) (controllers, etc.) (VERY good report; -v is verbose, -vv is very verbose

: lspci -tv  
(as root) shows tree

: lsusb
: lsusb -tv 
list usb devices,


Network:
: ifconfig -a


From GUI:
: ksysguard
KDE keyboard shortcut Ctrl-ESC (KDE)
New tabs can be added to monitor a variety of stuffs

Log files are stored in /var/log (in RHEL5 and other distros)
As 'root', you can view the system events in 'messages' file.
: sudo tail -20 /var/log/messages
: sudo vi /var/log/messages



A bash script for detecting the linux version and kernel is here, but may not work for all system.


#!/bin/sh
# Detects which OS and if it is Linux then it will detect which Linux Distribution.

OS=`uname -s`
REV=`uname -r`
MACH=`uname -m`

GetVersionFromFile()
{
       VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // `
}

if [ "${OS}" = "SunOS" ] ; then
       OS=Solaris
       ARCH=`uname -p`
       OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
elif [ "${OS}" = "AIX" ] ; then
       OSSTR="${OS} `oslevel` (`oslevel -r`)"
elif [ "${OS}" = "Linux" ] ; then
       KERNEL=`uname -r`
       if [ -f /etc/redhat-release ] ; then
               DIST='RedHat'
               PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
               REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
       elif [ -f /etc/SuSE-release ] ; then
               DIST=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`
               REV=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //`
       elif [ -f /etc/mandrake-release ] ; then
               DIST='Mandrake'
               PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
               REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
       elif [ -f /etc/debian_version ] ; then
               DIST="Debian `cat /etc/debian_version`"
               REV=""

       fi
       if [ -f /etc/UnitedLinux-release ] ; then
               DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
       fi

       OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})"

fi

echo ${OSSTR} 


from: http://www.novell.com/coolsolutions/feature/11251.html 
http://www.unix.com/unix-advanced-expert-users/21468-machine.html?t=21468#post83185


No comments:

Post a Comment