#! /bin/bash
# unset any variable which system could be using
# Clear the Screen
While getopts IVH name
Do
Case $name in
i) iopt=1;;
v) vopt=1;;
h) hopt=1;;
*) echo "Invalid arg";;
Esac
Done
#
if [[!-Z $iopt]]
Then
{
wd=$ (PWD)
BaseName "$ (test-l" $ "&& readlink" $ "| | echo "$") ">/tmp/scriptname
scriptname=$ (ECHO-E-n $wd/&& cat/tmp/scriptname)
Su-c "CP $scriptname/usr/bin/monitor" root && echo "congratulations! Script installed, now run monitor Command "| | echo "Installation Failed"
}
Fi
if [[!-Z $vopt]]
Then
{
Echo-e "Tecmint_monitor version 0.1\ndesigned by tecmint.com\nreleased under Apache 2.0 License"
}
Fi
if [[!-Z $hopt]]
Then
{
Echo-e "-I Install Script"
Echo-e "-V Print version information and exit"
Echo-e "-H Print Help (this information) and exit"
}
Fi
if [[$#-eq 0]]
Then
{
Clear
unset tecreset OS architecture kernelrelease internalip externalip nameserver loadaverage
# Define Variable Tecreset
tecreset=$ (Tput sgr0)
# Check if connected to the Internet or not
Ping-c 1 www.baidu.com &>/dev/null && echo-e ' \e[32m ' "Internet: $tecreset Connected" | | echo-e ' \E[32M ' "Internet: $tecreset Disconnected"
# Check OS Type
os=$ (Uname-o)
Echo-e ' \e[32m ' "Operating System Type:" $tecreset $os
# Check OS Release Version and Name
###################################
os= ' Uname-s '
rev= ' Uname-r '
Mach= ' Uname-m '
GetVersionFromFile ()
{
Version= ' Cat $ | 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/et C/redhat-release]; Then
dist= ' RedHat '
psuedoname= ' cat/etc/redhat-release | sed s/.*\ (//| sed s/\)//'
rev= ' Cat/etc/redhat-rele ASE | 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/deb Ian_version]; Then
dist= "Debian ' cat/etc/debian_version '"
rev= ""
Fi
If ${osstr} [-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
##################################
#cat/etc/os-release | grep ' name\| VERSION ' | Grep-v ' version_id ' | Grep-v ' Pretty_name ' >/tmp/osrelease
#echo-N-E ' \e[32m ' "OS Name:" $tecreset && cat/tmp/osrelease | Grep-v "VERSION" | Grep-v Cpe_name | Cut-f2-d\ "
#echo-N-E ' \e[32m ' "OS Version:" $tecreset && cat/tmp/osrelease | Grep-v "NAME" | Grep-v Ct_version | Cut-f2-d\ "
Echo-e ' \e[32m ' OS Version: ' $tecreset $OSSTR
architecture=$ (UNAME-M)
Echo-e ' \e[32m ' "Architecture:" $tecreset $architecture
kernelrelease=$ (UNAME-R)
Echo-e ' \e[32m ' "Kernel Release:" $tecreset $kernelrelease
Echo-e ' \e[32m ' "Hostname:" $tecreset $HOSTNAME
internalip=$ (Hostname-i)
Echo-e ' \e[32m ' "Internal IP:" $tecreset $internalip
externalip=$ (Curl-s Ipecho.net/plain;echo)
Echo-e ' \e[32m ' "External IP: $tecreset" $externalip
nameservers=$ (cat/etc/resolv.conf | sed ' 1 d ' | awk ' {print $} ')
Echo-e ' \e[32m ' "Name Servers:" $tecreset $nameservers
Who>/tmp/who
Echo-e ' \e[32m ' "Logged in Users:" $tecreset && cat/tmp/who
free-h | Grep-v + >/tmp/ramcache
Echo-e ' \e[32m ' "Ram Usages:" $tecreset
Cat/tmp/ramcache | Grep-v "Swap"
Echo-e ' \e[32m ' "Swap Usages:" $tecreset
Cat/tmp/ramcache | Grep-v "Mem"
df-h| grep ' filesystem\|/dev/sda* ' >/tmp/diskusage
Echo-e ' \e[32m ' "Disk Usages:" $tecreset
Cat/tmp/diskusage
loadaverage=$ (top-n 1-b | grep "Load average:" | awk ' {print $ $11 $ ')
Echo-e ' \e[32m ' "Load Average:" $tecreset $loadaverage
tecuptime=$ (Uptime | awk ' {print $3,$4} ' | cut-f1-d,)
Echo-e ' \e[32m ' "System Uptime days/(hh:mm):" $tecreset $tecuptime
unset tecreset OS architecture kernelrelease internalip externalip nameserver loadaverage
Rm/tmp/who/tmp/ramcache/tmp/diskusage
}
Fi
Shift $ (($OPTIND-1))
The # Shift command is used to move (move left) the parameter. can view http://blog.csdn.net/zhu_xun/article/details/24796235
#
monitor.sh Java Scripting Learning