这个脚本用于快速收集系统信息,相当给力,省的每次敲命令。。。
#!/bin/bash
################################################################################
#
# This script captures basic information for when a problem occurs.
# It can be used any time a problem occurs, as root or as a mortal user.
#
################################################################################
usage="Usage: vacuum [ -thorough | -perf | -hang <pid> | -trap | -error <cmd> ]"
mode_thorough=0
mode_perf=0
mode_hang=0
mode_trap=0
mode_error=0
topdir="" # The data collection directory
if [ -n $HOME ]
then
topdir=$HOME/investigations
else
topdir=~/investigations/$i
fi
if [ $# -gt 0 ]
then
while true ; do
case $1 in
"-thorough" )
mode_thorough=1
shift
;;
"-perf" )
mode_perf=1
mode="PERF"
shift
;;
"-hang" )
mode_hang=1
shift
if [ $# -le 0 ]
then
echo $usage
exit 2
fi
pid=$1
shift
;;
"-trap" )
mode_trap=1
shift412 Data Collection Script
;;
"-error" )
mode_error=1
shift
if [ $# -le 0 ]
then
echo $usage
exit 2
fi
cmd=$1
shift
;;
* )
echo $usage
exit 2
;;
esac
if [ $# -le 0 ]
then
break ;
fi
done
fi
if [ ! -n $USER ]
then
USER=‘whoami‘
fi
################################################################################
## Create the appropriate directory for this problem
################################################################################
i=0
invdir=$topdir/$i
while [ -d $invdir ]
do
let "i = i + 1"
invdir=$topdir/$i
done
echo Investigation directory: $invdir
################################################################################
## Create data directory, src directory and the investigation log
################################################################################
mkdir $invdir
mkdir $invdir/src
datadir=$invdir/data413
invlog=$invdir/log
mkdir $datadir
touch $invlog
echo "################################################################################"
>> $invlog
echo "## Header
##" >> $invlog
echo "################################################################################"
>> $invlog
echo "Problem number : $i" >> $invlog
echo -n "Time of data collector run : " >> $invlog
date >> $invlog
echo "Data collector run as : \"$0 $1 $2\" " >> $invlog
################################################################################
## Ready to go...
################################################################################
function collectFile
{
local comment=$1
local fileName=$2
local output=""
echo -n "COLLECT: $fileName ($comment) ... " >> $invlog
output='cp $fileName $datadir 2>&1'
if [ $? -ne 0 ]
then
echo "failed." >> $invlog
echo "output from copy:" >> $invlog
echo '{' >> $invlog
echo $output >> $invlog
echo '}' >> $invlog
else
echo "success." >> $invlog
fi
echo >> $invlog
}
function runCommand
{
local comment=$1
local cmd=$2
echo "RUNCMD: $cmd ($comment) ... " >> $invlog
echo '{' >> $invlog
$cmd 2>&1 >> $invlog 2>&1
echo '}' >> $invlog
echo >> $invlog
}
function doQuickCollect
{
echo >> $invlog
echo "################################################################################"
>> $invlog
echo "## Quick Collect ##" >> $invlog
echo "################################################################################"
>> $invlog
#Environmental information
runCommand "Environment variables" "/usr/bin/env"
#Network information
collectFile "DNS resolution configuration file" "/etc/resolv.conf"
collectFile "Name service switch configuration file" "/etc/nsswitch.conf"
collectFile "Static table lookup file" "/etc/hosts"
collectFile "TCP/IP services file" "/etc/services"
runCommand "Interface information" "ifconfig -a"
runCommand "Interface information (no DNS)" "/bin/netstat -i -n"
runCommand "Socket information" "/bin/netstat -an"
runCommand "Extended socket information" "/bin/netstat -avn"
runCommand "Socket owner information" "/bin/netstat -p"
runCommand "Network routing table" "/bin/netstat -rn"
runCommand "Network statistics" "/bin/netstat -s"
runCommand "Extended routing information" "/bin/netstat -rvn"
## the grep commands below look odd but it is a simple trick to get the contents of
## everything under specific directories415
runCommand "Network information from /proc" "/usr/bin/find /proc/net -type f -exec /bin/grep -Hv '^$' {} "
runCommand "System information from /proc" "/usr/bin/find /proc/sys -type f -exec /bin/grep -Hv '^$' {} "
runCommand "SYSV IPC info from /proc" '/usr/bin/find /proc/sysvipc -type f -exec /bin/grep -Hv ^$ {} ;'
#File system information
runCommand "Type information" "/bin/df -lT"
runCommand "Usage information" "/bin/df -lk"
runCommand "Inode information" "/bin/df -li"
runCommand "Share information" "/usr/sbin/showmount -e"
runCommand "SCSI and IDE disk partition tables" "/sbin/fdisk -l /dev/sd* /dev/hd*"
runCommand "NFS statistic" "/usr/sbin/nfsstat -cnrs"
collectFile "Filesystems supported by the kernel" "/proc/filesystems"
collectFile "Export file" "/etc/exports"
collectFile "Mount file" "/etc/fstab"
collectFile "Partition information" "/proc/partitions"
#Kernel information
runCommand "User (resource) limits" "ulimit -a"
runCommand "IPC information" "/usr/bin/ipcs -a"
runCommand "Loaded module info" "/sbin/lsmod"
runCommand "IPC resource limits" "/usr/bin/ipcs -l"
runCommand "Kernel information" "/sbin/sysctl -a"
runCommand "Memory usage" "/usr/bin/free"
runCommand "Uptime" "/usr/bin/uptime"
runCommand "System name, etc" "/bin/uname -a"
runCommand "Current users" "/usr/bin/w"
runCommand "Process listing" "/bin/ps auwx"
runCommand "Recent users" "/usr/bin/last|/usr/bin/head -100"
runCommand "Contents of home directory" "/bin/ls -lda $HOME"
runCommand "Host ID" "/usr/bin/hostid"
collectFile "Kernel limits specified by the user" "/etc/sysctl.conf"
collectFile "Load average" "/proc/loadavg"
collectFile "I/O memory map" "/proc/iomap"
collectFile "I/O port regions" "/proc/ioports"
collectFile "Interrupts per each IRQ" "/proc/interupts"
collectFile "CPU status" "/proc/cpuinfo"
collectFile "Memory usage" "/proc/meminfo"
collectFile "Swap partition information" "/proc/swaps"
collectFile "Slab information" "/proc/slabinfo"
collectFile "Lock information" "/proc/locks"
collectFile "Module information" "/proc/modules"
collectFile "Version information" "/proc/version"
collectFile "System status information" "/proc/stat"
collectFile "PCI information" "/proc/pci"
#Version information
runCommand "Package information" "/bin/rpm -qa"
#Misc
collectFile "Main syslog file" "/var/log/messages"
collectFile "Syslog configuration file" "/etc/syslog.conf"
}
function doThoroughCollect
{
echo >> $invlog
echo "################################################################################"
>> $invlog
echo "## Thorough Collect ##" >> $invlog
echo "################################################################################"
>> $invlog
runCommand "Virtual memory statistics" "/usr/bin/vmstat 2 5"
runCommand "I/O statistics" "/usr/bin/iostat 2 5"
runCommand "Extended I/O statistics" "/usr/bin/iostat -x 2 5"417
runCommand "CPU statistics" "/usr/bin/mpstat -P ALL 2 5"
runCommand "System activity" "/usr/bin/sar -A 2 5"
}
function doPerfCollect
{
echo >> $invlog
echo "################################################################################"
>> $invlog
echo "## Performance Collect ##" >> $invlog
echo "################################################################################"
>> $invlog
# Add specific commands here
}
function doHangCollect
{
echo >> $invlog
echo "################################################################################"
>> $invlog
echo "## Hang Collect ##" >> $invlog
echo "################################################################################"
>> $invlog
# NOTE: $pid contains the process ID of the process that is hanging
## check whether the process actually exists
kill -0 $pid 2>/dev/null 1>/dev/null
if [ ! $? -eq 0 ]
then
echo "Process ID \"$pid\" not found."
exit 3
fi
# Add specific commands here
}
function doErrorCollect
{
echo >> $invlog
echo "################################################################################"
>> $invlog
echo "## Error Collect ##" >> $invlog
echo "################################################################################"
>> $invlog
# NOTE: $cmd contains the name of the command line that apparently produces an error
# Add specific commands here
}
function doTrapCollect
{
echo >> $invlog
echo "################################################################################"
>> $invlog
echo "## Trap Collect ##" >> $invlog
echo "################################################################################"
>> $invlog
# Add specific commands here
}
######################################MAIN SCRIPT BODY######################################
## Do the basics first, then anything else that might be needed
##
doQuickCollect
if [ $mode_thorough -eq 1 ]
then
echo "Collecting thorough information"
doThoroughCollect
fi
if [ $mode_perf -eq 1 ]
then
echo "Collecting perf information"
doPerfCollect
fi
if [ $mode_hang -eq 1 ]
then
echo "Collecting hang information" doHangCollect
fi
if [ $mode_trap -eq 1 ]
then
echo "Collecting trap information"
doTrapCollect
fi
if [ $mode_error -eq 1 ]
then
echo "Collecting error information"
doErrorCollect
fi
echo >> $invlog
echo "################################################################################"
>> $invlog
echo "##End of Data Collection (the rest is for userinvestigation)##" >> $invlog
echo "################################################################################"
>> $invlog
分享到:
相关推荐
为了避免这种情况,你可以定期检查你的上网详细记录,登录`http://172.40.254.200:8080/selfservice`,查看是否有0.0.0.0的IP记录。如果有,这可能导致你被拉入黑名单。 对于北校区和南校区的教学区,可能需要使用`...
Python作为一种强大的脚本语言,不仅可以用于日常的数据处理,还能帮助我们构建系统级的服务。在这个主题中,我们将深入探讨如何利用Python在Windows环境下创建服务程序来实现计划任务,以及与Linux的crontab进行...
我们首先来看下全部代码: # -*- coding: cp936 -*- import win32serviceutil import win32service import win32event class test1(win32serviceutil.... win32serviceutil.ServiceFramework.__init__(self, args)
目前市场上的应用软件中有超过一半是面向网络的应用,如数据库服务器、游戏、Java Servlets 和 Applets、CGI 脚本等。数据通信不再是两台机器(本地网络或互联网)之间的奇技淫巧,而是日常生活中不可或缺的一部分。...
- 执行`service tomcat6 restart`命令以重启Tomcat服务。 **5. 重新编译Nutch** - 转到Nutch主目录下,执行`ant runtime`命令来重新编译整个项目。 **6. 清理旧数据** - 删除HBase中的`webpage`表以及Solr服务的...
6. **自我服务(Self Service)**: 提供一个用户界面,让用户自己管理部分设置和软件安装,如请求应用、更新密码或报告问题。 7. **集成(Integration)**: JAMF可以与Active Directory、LDAP、MDM(移动设备管理)...
用户通常会在一个运行Linux的操作系统上进行安装,如Raspberry Pi或虚拟机。安装过程中会涉及Python环境的设置,包括安装Python 3.x,以及配置pip(Python的包管理器)来安装Home Assistant的核心库。 一旦安装完成...
sudo docker swarm init --advertise-addr ${self.private_ip} EOF } ``` 这段代码会创建指定数量的EC2实例,并在启动时安装Docker并初始化Swarm节点。此外,还需要配置安全组以允许必要的网络通信,以及定义子网...
DTED:地面高度数字数据(图形的数据格式)文件 DTF:Symantec Q&A相关的数据库数据文件 DTM:DigiTrakker模块文件 DUN:Microsoft拔号网络导出文件 DV:数字视频文件(MIME) DWG:AutoCAD工程图文件;AutoCAD...