Shell script to General FreeBSD and Linux System information

in Categories Monitoring last updated February 26, 2009

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.


Share this on:

9 comment

  1. 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

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

  3. 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?

    1. 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/dmesg.today no longer has the info it wants.

  4. 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?

    Have a question? Post it on our forum!