首页 技术 正文
技术 2022年11月16日
0 收藏 372 点赞 4,733 浏览 2697 个字

使用SHELL脚本进行检查服务开启情况

#!/bin/bash
#需要首先安装 yum install nmap -y#检查指定端口是否开启
function checkPortStatus()
{
status=`nmap -sS 127.0.0.1 -p $ | grep open | awk '{print $2}'`
if [ "$status" != "open" ];
then
return ;
else
return ;
fi
}checkPortStatus
echo $?checkPortStatus
echo $?

调用python发送QQ邮件的邮件(可以防止垃圾邮件屏蔽)

#-*-coding:utf--*-#===============================================================================
# 导入smtplib和MIMEText
#===============================================================================
from email.MIMEText import MIMEText
from email.Header import Header
import smtplib, datetime,sys#===============================================================================
# 要发给谁,这里发给1个人
#===============================================================================
mailto_list=["10402852@qq.com"]#===============================================================================
# 设置服务器,用户名、口令以及邮箱的后缀
#===============================================================================
mail_host="smtp.qq.com"
mail_user=""
mail_pass="*************"
mail_postfix="qq.com"#===============================================================================
# 发送邮件
#===============================================================================
def send_mail(to_list,sub,content):
'''
to_list:发给谁
sub:主题
content:内容
send_mail("10402852@qq.com","sub","content")
'''
me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content)
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ";".join(to_list)
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me, to_list, msg.as_string())
s.close()
return True
except Exception, e:
print str(e)
return False
if __name__ == '__main__':
if send_mail(sys.argv[1],sys.argv[2],sys.argv[3]):
print "发送成功"
else:
print "发送失败"

测试用例:

[root@199 huanghai]# python mail.py 10402852@qq.com 黄海的测试标题 黄海的测试内容
发送成功

watch.py 监控CPU,内存,磁盘等情况

#!/usr/bin/python
#fileName:getinfoinsh.py
#get cpu,meminfo from top command.import os
import timedef getinfointop():
topp=os.popen("top -n1|grep -E '^Cpu|^Mem'")
toppstr=topp.read()
replacestr=["\x1b","[m","\x0f","[K"]
# replace the str cannt be printed.
for item in replacestr:toppstr=toppstr.replace(item,'') splitstr=toppstr.split("\n") cpuinfo=splitstr[].split()
meminfo=splitstr[].split()
info=(cpuinfo[].strip(','),cpuinfo[].strip(','),cpuinfo[].strip(','),meminfo[],meminfo[],meminfo[])
return infodef getinfoindh(): dhplines=[]
for i in os.popen("df -h"):
dhplines.append(i.strip())
return dhplinesif __name__=='__main__':
info=getinfointop()
diskinfo=getinfoindh()
print 'cpu info:'
print "user cpu used:",info[]
print "system cpu used:",info[]
print "free cpu:",info[]
print ''
print 'Mem info:'
print "used mem:",info[]
print "free mem:",info[]
print "total mem:",info[]
print ''
print 'disk info:'
for i in diskinfo:print i
print ''
print 'time:', time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time()))
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,105
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,582
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,429
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919