shell 脚本监控系统性能以及信息
#!/bin/bash mo=`date | cut -c 5-10` d=`date +%d` yd=`date -d yesterday +%d` echo "max mem" > /script/dalirepo sar -r -f /var/log/sa/sa$yd | cut -c 36-43 | sort -n | tail -n 1 >> /script/dalirepo echo "current mem" >> /script/dalirepo sar -r -f /var/log/sa/sa$d | cut -c 36-43 | tail -n 2 | head -n 1 >> /script/dalirepo echo "max cpu" >> /script/dalirepo sar -f /var/log/sa/sa$yd | cut -c 26-31 | sort -n | tail -n 1 >> /script/dalirepo echo "current cpu" >> /script/dalirepo sar -f /var/log/sa/sa$d | cut -c 26-31 | tail -n 2 | head -n 1 >> /script/dalirepo echo "max load" >> /script/dalirepo sar -q -f /var/log/sa/sa$yd | cut -c 36-44 | sort -n | tail -n 1 >> /script/dalirepo echo "current load " >> /script/dalirepo sar -q -f /var/log/sa/sa$d | cut -c 36-44 | tail -n 2 | head -n 1 >> /script/dalirepo df -h >> /script/dalirepo ps -ef | grep rsync >> /script/dalirepo echo "messages log" >> /script/dalirepo cat /var/log/messages | grep "$mo" | grep "error\|warning\|failure\|restart\|stop\|reboot" >> /script/dalirepo echo "secure log" >> /script/dalirepo cat /var/log/secure | grep "$mo" | grep "error\|warning\|failure\|restart\|stop\|reboot" >> /script/dalirepo echo "cron log" >> /script/dalirepo cat /var/log/cron | grep "$mo" | grep "error\|warning\|failure\|restart\|stop\|reboot" >> /script/dalirepo echo "services log" >> /script/dalirepo cat {/var/log/httpd/error_log,/var/log/httpd/ssl_error_log,/var/log/mysqld.log,/var/log/vsftpd.log,/var/log/yum.log} | grep "$mo" | grep "error\|warning\|failure\|restart\|stop \|reboot" >> /script/dalirepo mail -s subjectname [email protected],[email protected] < /script/dalirepo
把收集到的系统性能信息 写到/script/dalirepo 文件里,文件以文件的形式发送到各个需要接受的邮箱
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。