CentOS中文网

快速获得服务器基本信息shell脚本

CentOS中文网 https://www.centos.net.cn 2015-06-16 02:01 出处:网络 编辑:#iCMS
先上图后上shell脚本(适用于centos和debian系列) catcheck.sh #!/bin/bash #--------------------------------------------------

先上图后上shell脚本(适用于centos和debian系列)


快速获得服务器基本信息shell脚本


catcheck.sh

#!/bin/bash

#--------------------------------------------------

#Date:June152015

#Author:jimmygong

#Mail:jimmygong@taomee.com

#Function:

#Version:1.0

#apt-get-yinstalldmidecode--force-yesoryum-yinstalldmidecode

#apt-get-yinstallpciutils--force-yesoryum-yinstallpciutils

#apt-get-yinstallcurl--force-yesoryum-yinstallcurl

#--------------------------------------------------

set-onounset

line='======================================================================'

bluecolor='E[1;32m'

if[[`id-u`-ne0]]

then

echo"sctiptsneedroot"

exit0

fi

functionos()

{

manufacturer=$(dmidecode-ssystem-manufacturer)

product=$(dmidecode-ssystem-product-name)

sn=$(dmidecode-ssystem-serial-number)

nu=$(dmidecode|grep"Height")

kernel=$(uname-r)

if[[-e/etc/debian_version]]

then

release1=$(cat/etc/debian_version)

echo-e"${bluecolor}"Os:"Debian${release1}n${line}"

elif[[-e/etc/redhat-release]]

then

release2=$(cat/etc/redhat-release)

echo-e"${bluecolor}"Os:"${release2}n${line}"

else

echo"unkownrelease"

fi

if[[-e/boot/grub/menu.lst]]

then

grub1=$(cat/boot/grub/menu.lst|egrep-v"^#|^$")

echo-e"Grub:${grub1}n${line}"

else

grub2=$(cat/etc/default/grub|egrep-v"^#|^$")

echo-e"Grub:${grub2}n${line}"

fi

echo-e"Manufacturer:${manufacturer}"

echo-e"Product:${product}"

echo-e"Sn:${sn}"

echo-e"U:${nu}n${line}"

}

functioncpu()

{

mode=$(getconfLONG_BIT)

counts=$(cat/proc/cpuinfo|grep"physicalid"|sort|uniq-c|wc-l)

cores=$(grep'cpucores'/proc/cpuinfo|uniq|awk-F:'{print$2}'|sed's/^[t]*//g')

processor=$(cat/proc/cpuinfo|grep"processor"|wc-l)

cpu=$(grep'modelname'/proc/cpuinfo|uniq|awk-F:'{print$2}'|sed's/^[t]*//g'|sed's/+//g')

echo-e"TotalOfPhysicalCpu:${counts}"

echo-e"NumberOfCpuCores:${cores}"

echo-e"NumberOfCpuProcessor:${processor}"

echo-e"PresentModeOfCpu:${mode}"

echo-e"CpuModel:${cpu}n${line}"

}

functionmem()

{

swap=$(cat/proc/meminfo|grepSwapTotal|awk-F:'{print$2}'|awk-F""'{print$1}')

swap=$(expr$swap/1024)

mem=$(cat/proc/meminfo|grepMemTotal|awk-F:'{print$2}'|awk-F""'{print$1}')

memory=$(dmidecode|grep-i-C5'MemoryDevice'|grep-v"NoModuleInstalled"|grep-isize|grep-v"Range")

memoryslot=$(dmidecode|grep-i-C5'MemoryDevice'|grep"NoModuleInstalled"|wc-l)

mem=$(expr$mem/1024)

remem=$(free-m|grepcache|awk'/[0-9]/{print$4"MB"}')

echo-e"Memslot:${memoryslot}"

echo-e"NumberOfMem:${memory}"

echo-e"TotalOfMem:${mem}MB"

echo-e"TotalOfSwap:${swap}MB"

echo-e"RemainMem:${remem}n${line}"

}

functiondisk()

{

disk=$(fdisk-l|grep'Disk'|awk-F,'{print$1}'|sed's/Diskidentifier.*//g'|sed'/^$/d')

dftotal=$(df-h|grep"^/dev"|grep-vFilesystem)

dfinode=$(df-i|grep"^/dev"|grep-vFilesystem)

fstab=$(cat/etc/fstab|egrep-v"^#"'|media|proc'|awk'{print$1,$2,$3,$4}')

blkid=$(blkid)

echo-e"Disktotal:${disk}"

echo-e"Dftotal:n${dftotal}"

echo-e"Dfinode:n${dfinode}"

echo-e"Fstab:n${fstab}"

echo-e"Blkid:n${blkid}n${line}"

}

functiontimezone()

{

if[[-e/etc/timezone]]

then

timezone1=$(cat/etc/timezone)

echo-e"Timezone:${timezone1}n${line}"

else

timezone2=$(cat/etc/sysconfig/clock|grep-v"^#"|grep-v"^$"|awk-F"="'{print$2}')

echo-e"Timezone:${timezone2}n${line}"

fi

}

functionnetwork()

{

hostnamecmd=$(cat/proc/sys/kernel/hostname)

namecmd=$(cat/etc/resolv.conf|grep"nameserver"|egrep-v"^#|^$")

innerip=$(hostname-I)

outerip=$(curl-sip.cip.cc)

echo-e"Innerip:${innerip}"

echo-e"Outerip:${outerip}"

echo-e"${namecmd}"

echo-e"Hostname:${hostnamecmd}n${line}"

}

functionipmi()

{

lsmodipmi=$(lsmod|grepipmi)

if[[$?-eq0]]

then

ipmi=$(ipmitoollanprint|grep"IPAddress"|sed's/IPAddressSource.*//g'|sed'/^$/d')

echo-e"Ipmi:${ipmi}"

fi

tty=$(psaux|grep-w"ttyS1"|grep-vgrep||psaux|grep-w"ttyS0"|grep-vgrep)

if[[$?-eq0]]

then

echo-e"TtyS:${tty}n${line}"

fi

}

functionprocessid()

{

ss-s|head-2

net=`netstat-tpnl|grepLISTEN|awk'{print$4,$7}'`

echo-e"Netstattpnl:n${net}"

processnum=`ss-pl|awk-F:'{print$4}'|awk-F","'{print$2}'|sed'/^$/d'|wc-l`

for((i=1;i<=$processnum;i++))

do

pid=`ss-pl|awk-F:'{print$4}'|awk-F","'{print$2}'|sed'/^$/d'|sed-n$i'p'`

process=`pmap$pid|head-n2`

echo-e"Process:${process}"

done

echo-e${line}

}

functionswap()

{

echo-e"PidtSwaptProgame"

num=0

forpidin`ls-1/proc|egrep"^[0-9]"`

do

if[[$pid-le'30']]

then

continue

fi

program=$(ps-eopid,command|grep-w$pid|grep-vgrep|awk'{print$2}')

forswapin`grepSwap/proc/$pid/smaps2>/dev/null|awk'{print$2}'`

do

letnum=$num+$swap

done

echo-e"${pid}t${num}t${program}"

num=0

done|sort-nrk2|head

echo-e${line}

}

functionmima()

{

num=$(cat/etc/passwd|grep"/bin/bash"|awk-F:'{print$1}'|wc-l)

for((i=1;i<=$num;i++))

do

user=$(cat/etc/passwd|grep"/bin/bash"|awk-F:'{print$1}'|sed-n$i'p')

effeday=$(cat/etc/shadow|grep$user|awk-F:'{print$1,$5}')

echo-e"Shadow:${effeday}"

done

if[[-e/etc/sudoers]]

then

sudoers=$(cat/etc/sudoers|egrep-v"^#|^$")

echo-e"Sudoers:${sudoers}"

fi

chag=$(chage-lroot)

echo-e"ChageRoot:n${chag}n${line}"

}

functionlastlogin()

{

if[[-e/var/log/wtmp]]

then

last=$(last|head-n10)

echo-e"Last:n${last}n${line}"

fi

}

functionlimit()

{

limitcmd=$(cat/etc/security/limits.conf|egrep-v'^#|^$')

if[[$?-eq0]]

then

echo-e"Limitconf:n${limitcmd}n${line}"

fi

}

functiondiskcheck()

{

if[[-e/usr/local/sbin/MegaCli64]]

then

cmd="/usr/local/sbin/MegaCli64"

raid=`$cmd-cfgdsply-aALL|grep"RAIDLevel"|tail-1|awk-F:'{print$1":"$2}'`

disknum=`$cmd-cfgdsply-aALL|grep"NumberOfDrives"|awk-F:'{print$2}'`

onlinedisk=`$cmd-cfgdsply-aALL|grep-c"Online"`

faileddisk=`$cmd-AdpAllInfo-aALL-NoLog|awk'/FailedDisks/{print$4}'`

criticaldisk=`$cmd-AdpAllInfo-aALL-NoLog|awk'/CriticalDisks/{print$4}'`

case"$raid"in

"RAIDLevel:Primary-1,Secondary-0,RAIDLevelQualifier-0")

echo"RaidLevel:1";;

"RAIDLevel:Primary-0,Secondary-0,RAIDLevelQualifier-0")

echo"RaidLevel:0";;

"RAIDLevel:Primary-5,Secondary-0,RAIDLevelQualifier-3")

echo"RaidLevel:5";;

"RAIDLevel:Primary-6,Secondary-0,RAIDLevelQualifier-3")

echo"RaidLevel:6";;

"RAIDLevel:Primary-1,Secondary-3,RAIDLevelQualifier-0")

echo"RaidLevel:10";;

esac

echo"TotalDiakNumber:$disknum"

echo"OnlineDiskNumber:$onlinedisk"

echo"FailedDiskNumber:$faileddisk"

echo"CriticalDiskNumber:$criticaldisk"

$cmd-PDList-aALL|grep"Firmwarestate"

echo-e${line}

fi

}

functionlocalea()

{

if[[-e/etc/default/locale]]

then

locale1=$(cat/etc/default/locale|egrep-v"^#|^$")

echo-e"CurrLocale:${locale1}"

elif[[-e/etc/sysconfig/i18n]]

then

locale2=$(cat/etc/sysconfig/i18n|egrep-v"^#|^$")

echo-e"CurrLocale:${locale2}"

else

echo$LANG

fi

locale=`locale-a|wc-l`

echo-e"LocaleNum:${locale}n${line}"

}

functioncron()

{

user=$(psaux|grep-vUSER|awk'{print$1}'|sort-r|uniq)

echo-e"RunUser:n${user}n${line}"

path1="/var/spool/cron/crontabs"

path2="/var/spool/cron"

if[[-d$path1]]

then

foruserin$(ls-1$path1)

do

echo-e"$user:"

crontab-l-u$user

done

else

foruserin$(ls-1$path2)

do

echo-e"$user:"

crontab-l-u$user

done

fi

}

os

cpu

mem

disk

timezone

network

ipmi

processid

swap

mima

lastlogin

limit

diskcheck

localea

cron

exit0

0

精彩评论

暂无评论...
验证码 换一张
取 消