Shell script to General FreeBSD and Linux System information

in Monitoring

Shell script to display general FreeBSD and Linux System information such as, Hostname, OS version, Kernel version, Processor/CPU, Total RAM, System load, network interface, total logged in users, Hard disks, Runlevel etc in neat format.

How do I use the script?

You need to download following two files for FreeBSD operating systems:

  1. File # 1 Save this file as /usr/local/etc/bashmonscripts
  2. File # 2 : Save this file as /usr/local/etc/defaults.conf

For Linux system, you need to update /usr/local/etc/defaults.conf to point out exact binary path location. /usr/local/etc/bashmonscripts is nothing but functions library used by this script. bashmonscripts works under both Linux and FreeBSD.

#!/bin/bash
# Shell script to General FreeBSD and Linux System information such as:
# Hostname, OS version, Kernel version, Processor/CPU, Total RAM,
# System load, network interface, total logged in users, Hard disks,
# Runlevel etc. I will write separate scripts for detailed system
# information :D
# Copyright (c) 2005 nixCraft project
# This script is licensed under GNU GPL version 2.0 or above
# For more info, please visit:
#            http://cyberciti.biz/shell_scripting/bmsinstall.php
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
 
SPATH="/usr/local/etc/bashmonscripts"
INITBMS="$SPATH/defaults.conf"
[ ! -f $INITBMS ] && exit 1 || . $INITBMS
 
echo "Hostname:" $(getHostName)
echo "OS Name:" $($UNAME)
echo "OS Version:" $($UNAME -mr)
echo "Processor:" $(getCpuInfo)
echo "Total Physical Memory (RAM):" $(getRealRamInfo)
echo "System Load:" $(getSystemLoad)
echo "Date & Time:" $($DATE)
echo "Network interface:" $(getNumberOfInterfaces)
echo "Total logged in users:" $(getNumberOfLoggedInUsers)
echo "Total running process:" $(getNumberOfRunningProcess)
echo "Total SCSI/IDE disks:" $(getDiskDrives)
echo "Mounted partitions:" $(getNumberOfParittions)
echo "Loaded dynamic kernel modules/drivers:" $(getNumberOfKernelModules)
echo "OS Rulevel:" $(getOsRunLevel)
Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our email newsletter to make sure you don't miss a single tip/tricks.

{ 4 comments… read them below or add one }

Kevin September 18, 2008 at 7:14 pm

hi can someone tell me how to use this script.
I have done chmod + secript
and bash script.sh

its still doesnt work can someone enlighten me?

Reply

Bramhanand lingala February 26, 2009 at 11:03 am

you probably dont have the path specified in the above script /usr/local/etc/bashmonscript.

Reply

Vivek Gite February 26, 2009 at 12:48 pm

This page has been updated. Download other two files and you should able to run script.

Reply

Mystique March 9, 2009 at 4:43 pm

This doesn’t seem to work and I can not figure out why.. well I don’t ever see where SPATH is used..

15
16 SPATH=”/root/blah/bashmonscripts”
17 INITBMS=”/root/blah/defaults.conf”
18 [ ! -f $INITBMS ] && exit 1 || . $INITBMS
19

saving the above script as ’script’ and then making it 755.. and saving the other two files and naming them correctly..

and adding -x to the ’script’..

[~/blah]# 79 > ./script
+ SPATH=/root/blah/bashmonscripts
+ INITBMS=/root/blah/defaults.conf
+ ‘[' '!' -f /root/blah/defaults.conf ']‘
+ . /root/blah/defaults.conf
++ SHADOW_FILE=/etc/master.passwd
++ PASSWD_FILE=/etc/passwd
++ DF=/bin/df
++ DATE=/bin/date
++ HOSTNAME=/bin/hostname
++ CAT=/bin/cat
++ PS=/bin/ps
++ AWK=/usr/bin/awk
++ GREP=/usr/bin/grep
++ LASTLOG=/usr/bin/lastlog
++ ID=/usr/bin/id
++ UNAME=/usr/bin/uname
++ BASENAME=/usr/bin/basename
++ LAST=/usr/bin/last
++ LASTLOGIN=/usr/sbin/lastlogin
++ FIND=/usr/bin/find
++ UPTIME=/usr/bin/uptime
++ HEAD=/usr/bin/head
++ CUT=/usr/bin/cut
++ W=/usr/bin/w
++ WC=/usr/bin/wc
++ IFCONFIG=/sbin/ifconfig
++ DMESG=/sbin/dmesg
++ KLDSTAT=/sbin/kldstat
++ SYSCTL=/sbin/sysctl
++ IOSTAT=/usr/sbin/iostat
++ getHostName
./script: line 20: getHostName: command not found
+ echo Hostname:
Hostname:
++ /usr/bin/uname
+ echo ‘OS Name:’ FreeBSD
OS Name: FreeBSD
++ /usr/bin/uname -mr
+ echo ‘OS Version:’ 7.1-RELEASE-p2 i386
OS Version: 7.1-RELEASE-p2 i386
++ getCpuInfo
./script: line 23: getCpuInfo: command not found
+ echo Processor:
… etc

Where does it ever get/use/need SPATH?

Reply

Leave a Comment

Previous post: Shell script to Finding Accounts with No Password ( null password account )

Next post: Shell script to get uptime, disk , cpu , RAM , system load, from multiple Linux servers – output the information on a single server in html format