Shell Script To Read IP Address ( Find Ip Address Script )

in Categories Script last updated April 10, 2008
#!/bin/sh
# Shell script scripts to read ip address
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# Get OS name
OS=`uname`
IO="" # store IP
case $OS in
   Linux) IP=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;
   FreeBSD|OpenBSD) IP=`ifconfig  | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;
   SunOS) IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;
   *) IP="Unknown";;
esac
echo "$IP"

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.

#!/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)