Shell脚本监控Linux系统内存使用率
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
免费下载资源
·
Shell脚本如下:
#/bin/bash
#environment variable
source /etc/profile
#memory
bu=`free | awk 'NR==2{print $6}'`
ca=`free | awk 'NR==2{print $7}'`
us=`free | awk 'NR==2{print $3}'`
to=`free | awk 'NR==2{print $2}'`
mem=`expr "scale=2;($us-$bu-$ca)/$to" |bc -l | cut -d. -f2`
if(($mem >= 70))
then
msg="TIME:$(date +%F_%T)
HOSTNAME:$(hostname)
IPADDR:$(ifconfig |awk 'NR==2{print $2}')
MSG:内存high了high了!已经用了${mem}%"
echo $msg
/test/pymail.py $msg
fi
发送邮件脚本 pymail.py 内容如下:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
import smtplib
import email.mime.multipart
import email.mime.text
server = 'smtp.126.com'
port = '25'
def sendmail(server,port,user,pwd,msg):
smtp = smtplib.SMTP()
smtp.connect(server,port)
smtp.login(user, pwd)
smtp.sendmail(msg['from'], msg['to'], msg.as_string())
smtp.quit()
print('邮件发送成功email has send out !')
if __name__ == '__main__':
msg = email.mime.multipart.MIMEMultipart()
msg['Subject'] = '服务器报警请注意!'
msg['From'] = 'ron@126.com'
msg['To'] = 'xxx@139.com'
user = 'ron'
pwd = 'password'
content='%s\n%s' %('\n'.join(sys.argv[1:4]),' '.join(sys.argv[4:])) #格式处理,专门针对我们的邮件格式
txt = email.mime.text.MIMEText(content, _charset='utf-8')
msg.attach(txt)
sendmail(server,port,user,pwd,msg)
GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
已为社区贡献7条内容
所有评论(0)