一个可以简单收集服务器和SYBASE 信息的脚本
测试的系统环境是RHEL和SYBASE12.5.2,欢迎大家测试并修改。#!/usr/bin/env bash
#
#System and Sybase Report,write by westmstc@gmail.com
#data:2009.01.12 11:30
echo "Creating SysReport Folder"
if [ -e ~/SysReport ] && [ -d ~/SysReport ]
then : # if it exists and is a folder do nothing
else mkdir ~/SysReport
fi
rm -rf ~/SysReport/*.html
# Next we want to create the index.html file whether it exists or not to allow for updating it
# with new versions of the script
echo "Creating index.html"
cat > ~/SysReport/index.html << EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
<META NAME="Author" Content="Ray Parrish">
<TITLE>System Report</TITLE>
</HEAD>
<FRAMESET COLS = "21%,79% ">
<FRAME SRC="navigate.html" NAME="Navigate" RESIZE>
<FRAME SRC="Introduction.html" NAME="Modules" RESIZE>
</FRAMESET>
<NOFRAMES>
<BODY>
<P>
</BODY>
</NOFRAMES>
</HTML>
EOF
###########################Creating Introduction.html################################
echo "Creating Introduction.html"
cat > ~/SysReport/Introduction.html << EOF
<html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title>Introduction to System Report</title></head>
<body>
<center><p>Welcome, you are logged in $HOSTNAME as: $USER</center>
<table style="text-align: left; width: 100%;" border="2" cellpadding="2" cellspacing="2">
<tbody><tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255);">
</td></tr></tbody></table>
<br>
<br>
</body>
</html>
EOF
navigate()
{
cat >> ~/SysReport/navigate.html << EOF
<li><a href="$1.html " target="Modules">$2</a></li>
EOF
}
htmlfun()
{
echo "Creating ${1}info.html"
cat >> ~/SysReport/${1}info.html << EOF
<html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title>$1 Information</title></head>
<body>
<table style="text-align: left; width: 100%;" border="2" cellpadding="2"
cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 153, 255);">
$2
</td></tr>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255);"><pre>
EOF
# generate the out put from system file
$2>> ~/SysReport/${1}info.html
# add the end of the file
cat >> ~/SysReport/${1}info.html << EOF
</pre></td></tr></tbody></table></body></html>
EOF
}
navigateIntroduction"Introduction to System Report"
##################hardware info#########################
navigate hardinfo "Hardware Information"
htmlfunhard "dmesg"
##################cpu info#########################
navigate cpuinfo "Cpu Information"
htmlfuncpu "cat /proc/cpuinfo"
##################disk info#######################
navigate diskinfo"Disk Information"
htmlfundisk "df -h"
htmlfundisk "fdisk -l"
##################memory info#######################
navigate meminfo "MemoryInformation"
htmlfunmem "free -mo"
htmlfunmem "cat /proc/meminfo"
##################pcibusinfo#######################
navigate pciinfo "PcibusInformation"
htmlfunpci "lspci -t -v"
htmlfunpci "lspci -b -v"
##################usbdeviceinfo#######################
navigate usbinfo "UsbdeviceInformation"
htmlfunusb "lsusb -v"
##################networkinfo#######################
navigate netinfo "NetworkInformation"
htmlfunnet "ifconfig -a"
htmlfunnet "cat /etc/hosts"
htmlfunnet "netstat -rn"
htmlfunnet "netstat -in"
htmlfunnet "netstat -an"
#################modules info##########################
navigatemodinfo "Modules Information"
htmlfun mod "lsmod"
#################operate systeminfo#################
navigateopsysinfo "Opsys Information"
htmlfun opsys "cat/etc/issue"
htmlfun opsys "cat/boot/grub/device.map"
htmlfun opsys "uname -a"
htmlfun opsys "cat /etc/grub.conf"
htmlfun opsys "ps aux"
#################environment info#################
navigateenvinfo "Environment Information"
htmlfun env "set"
#################software info####################
navigatesoftinfo "Software Information"
htmlfun soft "/bin/rpm -qa --queryformat '%{NAME}-%{VERSION}-%{RELEASE}\t\t\t\t%{VENDOR}\t\t\t\t%{SIZE}bytes\t\t\t\t%{INSTALLTIME:day}\t\t\t\t%{URL}\t\t\t\t%{SUMMARY}\n' | sort"
#################logfileinfo####################
navigateloginfo "Logfile Information"
htmlfun log "cat /etc/syslog.conf"
htmlfun log "tail -n 100 /var/log/messages"
htmlfun log "last"
#################service info####################
navigatesrvinfo "Services Information"
touch ~/SysReport/service
SRVDIR=/etc/init.d
for SERVICE in `ls -1 ${SRVDIR}` ; do
case "${SERVICE}" in
functions | halt | killall | single| linuxconf| kudzu | bgpd | boot | reboot | single | nscd | \
halt.* | rc | boot.* | *rpmorig | *rpmnew | *rpmsave | *~ | *.orig)
;;
*)
if [ -x "${SRVDIR}/${SERVICE}" -a -f "${SRVDIR}/${SERVICE}" ]; then
echo "Service Name: ${SERVICE}" >> ~/SysReport/service
/usr/bin/env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SRVDIR}/${SERVICE}" status >> ~/SysReport/service 2>&1
echo >> ~/SysReport/service
echo "---------------------------------------------------------------------------" >> ~/SysReport/service
fi
;;
esac
done
htmlfun srv "chkconfig --list"
htmlfun srv "cat /$USER/SysReport/service"
rm ~/SysReport/service
#######################server performance info################
navigate perfinfo "Performance Information"
htmlfun perf "vmstat"
htmlfun perf "sar"
htmlfun perf "ipcs"
htmlfun perf "iostat"
htmlfun perf "cat /proc/slabinfo"
##########################check sybase########################
#请自己修改下面的参数以适合自己的环境
DSQUERY=`echo $DSQUERY`
SYBASE=/opt/sybase
ASE=ASE-12_5
OCS=OCS-12_5
DATAPWD=./
SAPASS=
PATH=$SYBASE/$OCS/bin:$SYBASE/$ASE/bin:$SYBASE/$ASE/install:/usr/sbin:/usr/bin:/bin:/sbin:/usr/bin/X11:.
export PATH SYBASE DSQUERY
sa_execsql()
{
echo $* >tmp$$
echo "go" >>tmp$$
echo "quit" >>tmp$$
isql -I ${SYBASE}/interfaces -P ${SAPASS}-Usa -w 2000 -itmp$$ -oinfo.dat
rm -f tmp$$
}
########################sybstatus info########################
navigate sybinfo "Sybase Status Information"
htmlfun syb "showserver"
########################dbsize info##################
navigate dbinfo "DatabasesizeInformation"
sa_execsql "sp_helpdb"
htmlfun db "cat info.dat"
########################sybase config info####################
navigate confinfo "Sybase ConfigInformation"
sa_execsql"sp_configure"
htmlfun conf "cat info.dat"
########################sybase sysmon info####################
navigate dbmoninfo "Sybase SysmonInformation"
sa_execsql"sp_sysmon '00:01:00' "
htmlfun dbmon "cat info.dat"
########################sybase device info####################
navigate devinfo "Sybase DeviceInformation"
sa_execsql"sp_helpdevice"
htmlfun dev "cat info.dat"
########################sybase proc info######################
navigate procinfo "Sybase Proc Information"
sa_execsql"sp_who"
htmlfun proc "cat info.dat"
########################sybase log info#######################
navigate sybloginfo "Sybase log Information"
htmlfun syblog "tail -n 500$SYBASE/$ASE/install/$DSQUERY.log"
#########################tar sysreprot########################
tar zcvf ~/SysReport.tar.gz~/SysReport/* > /dev/null
rm -rf ~/SysReport
rm -rf ~/*.dat
脚本如下
页:
[1]