Shell script to General FreeBSD and Linux System information

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.

# 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: 
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit for more information.
# -------------------------------------------------------------------------
[ ! -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)
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics via:
Category List of Unix and Linux commands
Disk space analyzers ncdu pydf
File Management cat
Firewall Alpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilities NetHogs dig host ip nmap
OpenVPN CentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Manager apk apt
Processes Management bg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searching grep whereis which
User Information groups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPN Alpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
9 comments… add one
  • esteban Aug 19, 2010 @ 23:58

    can anyone help with a similar script for Solaris 9/10 ? thanx

  • Naz Feb 10, 2010 @ 15:29

    Can someone please help me solve this by writing a script in freebsd.

    Immediately after installing a new server one of the things you should do is document exactly what files are suid. As part of your job monitoring the server you would want to know if any files on the server are suid. A file suddenly becoming suid when it was not originally is a sign that your server has been compromised. You will need a way to monitor for changes.

    What UNIX command will list all files that are suid on the server? What UNIX command will list all files that are sgid on the server? Hint: the set uid and set gid permissions are in the fourth octect of the permissions.

    After finding all of the files that have been setuid you would want to send the output to a file. This would be your baseline, that you would compare your daily runs to. Your daily run would also go to a file and then you would have to compare the two files, for any differences.

    If there is a difference between the original file (baseline) that you created and the new file you must send an email, using the mail utility, to your account with the results (or the differences)

    If the suid files on the server have not changed, send email with the subject line of “No Changes in suid”

    Schedule your shell script to run nightly in cron

  • kuldeep Nov 10, 2009 @ 9:10

    i m usind redhat linux5.0 .i want to install Mplayer to play can i install Mplayer and which rpm is used for this.please tell me

  • Daniel Gerzo Sep 7, 2009 @ 0:08


    maybe someone will find this useful:

  • Mystique Mar 9, 2009 @ 16:43

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

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

    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:
    ++ /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?

    • Larry Nov 10, 2009 @ 21:01

      Good, you figured out the problem with line 17. I added a line after 18 that duplicates line 18 but with INITBMS changed to SPATH.

      Still, the script only works right after you boot. If your system has been up for a while, /var/log/ no longer has the info it wants.

  • 🐧 Vivek Gite Feb 26, 2009 @ 12:48

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

  • Bramhanand lingala Feb 26, 2009 @ 11:03

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

  • Kevin Sep 18, 2008 @ 19:14

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

    its still doesnt work can someone enlighten me?

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.