- 论坛徽章:
- 0
|
本帖最后由 wangdonsy 于 2010-06-07 13:56 编辑
大概写了个脚本,用于收集操作系统和sybase 数据库的信息,由于对unixware 掌握的比较少,很多命令还不太清楚,欢迎各位继续补充和修改,以完善这个脚本.
- #!/usr/bin/env sh
- #
- #Unixware System and Sybase Check Report,write by westmstc@gmail.com
- #Version 1.0 2010.06.03
- #
- ##################################################################
- #说明:unixware信息收集和sybase(页面为2K)数据库检查脚本
- #在unixware 7.1.1 和 sybase 11.9.2 上测试通过
- #欢迎各位继续补充和修改,以完善这个脚本
- ##################################################################
- VER="Version 1.0"
- CUSTNAME="XXX公司XXX服务器"
- CKPATH=/tmp/`hostname`report
- export CKPATH
- if test $LOGNAME != "root"
- then
- echo "You must be root to use this script"
- exit
- fi
- echo "Creating SysReport Folder"
- if [ -d $CKPATH ]
- then : # if it exists and is a folder do nothing
- else
- mkdir -p $CKPATH
- fi
- # 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
- ###########################Creating index.html#######################################
- echo "Creating index.html"
- cat > $CKPATH/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="westmstc">
- <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 > $CKPATH/Introduction.html << EOF
- <html><head><meta content="text/html;charset=gb2312" http-equiv="Content-Type">
- <title>Introduction to System Report</title></head>
- <body>
- <center><p><font size="5">XXX公司客户巡检详单</font></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>
- <div class="block">
- <div align="right">
- <br><br>
- </div>
- <ul>
- <li><font size="5"><span class="label">客户名称:</span>$CUSTNAME</font></li>
- <li><font size="5"><span class="label">主机名称:</span>`hostname`</font></li>
- <li><font size="5"><span class="label">巡检时间:</span>`date +"%Y-%m-%d %T %a"`</font></li>
- <li><font size="5"><span class="label">检测用户:</span>$LOGNAME</font></li>
- <li><font size="5"><span class="label">脚本版本:</span>$VER</font></li>
- </ul></div></br>
- <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>
- <p align="center"><br>
- 说明:对本巡检详单有任何问题,请联系 QQ:xxxxxxxxx 邮箱:xxxxxxxxxxxx</p>
- <p align="center"> 联系电话:029-xxxxxxxxxx</br></p></body></html>
- EOF
- ###########################Creating navigate.html################################
- navigate()
- {
- cat >> $CKPATH/navigate.html << EOF
- <li><a href="$1.html " target="Modules">$2</a></li>
- EOF
- }
- htmlfun()
- {
- echo "Checking ${1}info"
- cat >> $CKPATH/${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 >> $CKPATH/${1}info.html
- # add the end of the file
- cat >> $CKPATH/${1}info.html << EOF
- </pre></td></tr></tbody></table></body></html>
- EOF
- }
- ############################# check operate system info######################
- navigate Introduction "Introduction to System Report"
- ##################hardware info#########################
- navigate hardinfo "Hardware Information"
- htmlfun hard "hw"
- htmlfun hard "prtconf"
- htmlfun hard "sdiconfig -l"
- ##################cpu info##############################
- navigate cpuinfo "Cpu Information"
- htmlfun cpu "/sbin/psrinfo -v"
- ##################disk info#############################
- navigate diskinfo "Disk Information"
- htmlfun disk "df -k"
- htmlfun disk "dfspace"
- htmlfun disk "mount -v"
- htmlfun disk "cat /etc/vfstab"
- ##################memory info###########################
- navigate meminfo "Memory Information"
- htmlfun mem "prtconf | grep "Memory""
- htmlfun mem "swap -l"
- ##################pcibus info##########################
- navigate pciinfo "Pcibus Information"
- htmlfun pci "hw -r pci"
- ##################network info#########################
- navigate netinfo "Network Information"
- htmlfun net "ifconfig -a"
- htmlfun net "cat /etc/hosts"
- htmlfun net "cat /etc/resolv.conf"
- htmlfun net "netstat -rn"
- htmlfun net "netstat -s"
- htmlfun net "netstat -in"
- htmlfun net "netstat -an"
- #################op system info###################
- navigate opsysinfo "Opsys Information"
- htmlfun opsys "cat /etc/issue"
- htmlfun opsys "uname -acdilmnprsvAX"
- htmlfun opsys "ulimit -a"
- htmlfun opsys "uptime"
- htmlfun opsys "ps -ef"
- #################boot info########################
- navigate bootinfo "boot Information"
- htmlfun boot "ls -l /stand"
- htmlfun boot "cat /stand/boot"
- #################cron info########################
- navigate croninfo "Cron Information"
- htmlfun cron "crontab -l"
- #################environment info#######################
- navigate envinfo "Environment Information"
- htmlfun env "set"
- htmlfun env "cat /etc/profile"
- #################software info##########################
- navigate softinfo "Software Information"
- htmlfun soft "pkginfo"
- #################logfile info##########################
- navigate loginfo "Logfile Information"
- htmlfun log "cat /etc/syslog.conf"
- htmlfun log "tail -n 100 /var/adm/syslog"
- htmlfun log "last"
- #######################server performance info###########
- navigate perfinfo "Performance Information"
- htmlfun perf "sar"
- htmlfun perf "sar -d"
- htmlfun perf "sar -b"
- htmlfun perf "ipcs"
- htmlfun perf "ps -eL"
- ############################# check sybase database info#####################
- ##########################check sybase##################
- # 收集sybase 数据库信息
- #SYBASE SAPASS DSQUERY 根据实际情况修改
- ########################################################
- SYBASE=/sybase
- DATAPWD=./
- SAPASS=stserver
- DSQUERY=stserver
- PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:${SYBASE}/bin:${SYBASE}/install:/usr/bin/X11:/bin:.
- export PATH SYBASE DSQUERY
- sa_execsql()
- {
- echo $* >tmp$$
- echo "go" >>tmp$$
- echo "quit" >>tmp$$
- isql -I ${SYBASE}/interfaces -P ${SAPASS} -Usa -w2000 -Jiso_1 -S ${DSQUERY} -s'|' -itmp$$ -oinfo.dat
- rm -f tmp$$
- }
- ########################sybstatus info##################
- navigate sybinfo "Sybase Status Information"
- htmlfun syb "showserver"
- sa_execsql "select @@version"
- htmlfun syb "cat info.dat"
- ########################database info###################
- navigate dbinfo "Database Information"
- sa_execsql "sp_helpdb"
- htmlfun db "cat info.dat"
- ########################dbsize info###################
- navigate dbsizeinfo "Databasesize Information"
- isql -I ${SYBASE}/interfaces -P ${SAPASS} -Usa -w2000 -Jiso_1 -S ${DSQUERY} -s'|' -oinfo.dat <<EOF
- set nocount on
- go
- use master
- go
- select getdate() "update date:"
- go
- select dbid, db_name(dbid) "dbname",
- convert(numeric(10,2),sum(size) / 512.0) "dbsizeMB",
- convert(numeric(10,2),sum (case when segmap&~4=0 then 0 else size end) / 512.0) "datadevsizeMB",
- convert(numeric(10,2),sum (case when segmap&~4=0 then 0 else unreservedpgs end) / 512.0) "datadevfreeMB",
- convert(numeric(10,2),100.0 * (sum (case when segmap&~4=0 then 0 else unreservedpgs end) / 512.0) / (0.000000001+sum (case when segmap&~4=0 then 0 else size end) / 512.0)) "datadevfree%",
- convert(numeric(10,2),sum (case when segmap=4 then size else 0 end) / 512.0) "logdevsizeMB",
- convert(numeric(10,2),sum (case when segmap=4 then unreservedpgs else 0 end) / 512.0) "logdevfreeMB",
- convert(numeric(10,2),100.0 * (sum (case when segmap=4 then unreservedpgs else 0 end) / 512.0) / (0.0000001+sum (case when segmap=4 then size else 0 end) / 512.0)) "logdevfree%"
- from sysusages group by dbid
- go
- exit
- go
- EOF
- htmlfun dbsize "cat info.dat"
-
- ########################sybase device info##############
- navigate devinfo "Sybase Device Information"
- sa_execsql "sp_helpdevice"
- htmlfun dev "cat info.dat"
- ########################sybase config info##############
- navigate confinfo "Sybase Config Information"
- sa_execsql "sp_configure"
- htmlfun conf "cat info.dat"
- ########################sybase sysmon info##############
- #navigate dbmoninfo "Sybase Sysmon Information"
- #sa_execsql "sp_sysmon '00:01:00' "
- #htmlfun dbmon "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/install/errorlog"
- ############################# collect system log file #####################
- ####################### collect system log ############
- mkdir -p $CKPATH/log
- cp -r /var/adm/syslog $CKPATH/log
- #########################tar SysSybreport dir###########
- cd $CKPATH
- tar -cvf - * | compress > ${CKPATH}`date +"%Y-%m-%d"`.Z
- cd ..
- rm -rf info.dat
- rm -rf $CKPATH
复制代码 |
|