您的位置:首页 > 运维架构 > Shell

使用shell脚本获取系统运行状态

2014-06-13 08:24 471 查看
#!/bin/bash
#
#snapshot_states - produces a report for system states
##################################################
# Set Scripts Variables
DATE=`date +%m%d%Y`
DISKS_TO_MONITOR="/dev/sda1 /dev/sda7"
MAIL=`which mail`
MAIL_TO=user
REPORT=/home/user/Documents/snapshot_states_$DATE.rpt
#
#####################################
# Create Report FIles
#
exec 3>&1  #Save file descriptor
#
exec 1 > $REPORT
echo
echo -e "\t\t Daily System Report"
echo
#
############################################
echo -e "Today is "`date +%m/%d/%Y`
echo
#####################################
#1) Gather System Uptime Statistics
#
echo -e "System Has Been \c"
uptime | sed -n '/,/s/,/ /gp'|\
gawk '{if($4=="days" || $4=="day")
{print $2,$3,$4,$5}
else
{print $2,$3}
}'

######################################
# 2) Gather Disk Usage Statistics
#
echo
for DISK in $DISKS_TO_MONITOR
do
echo -e "$DISK usage:\c"
df -h $DISK |sed -n '/% \//p'|gawk '{print $5}'
done

#####################################
# 3) Gather Memory Usage Statistics
#
echo
echo -e "Memory Usage:\c"
#
free |sed -n '2p'|gawk 'x=int(($3/$2)*100) {print x}'|\
sed 's/$/%/'

##################################
# 4) Gather number of zombie processes

echo
ZOMBIE_CHECK=`ps -al | gawk '{print $2,$4}'|grep Z`

if [ "$ZOMBIE_CHECK" = "" ];then
echo "No Zombie Process on System at this time"
else
echo "Current System Zombie Processes"
ps -al |gawk '{print $2,$4}'|grep Z
fi

echo
exec 1>&3
$MAIL -a $REPORT -s "System Statistics Report for $DATE"\
--$MAIL_TO </dev/null

rm -f $REPORT
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: