python邮件收发SAMPLE
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import os, socket
from time import localtime, strftime
from smtplib import SMTP
smtp = SMTP()
#smtp.set_debuglevel(debuglevel)
smtp.connect('d.g.g.g', 25)
smtp.login(')
from_addr = "234<234@f.f>"
to_addr_normal = ["234@f.f","234@f.f"]
to_addr_alert = ["234@f.f","s234@f.fm"]
# Limit in MiB
LIMIT=200000;
#Define current Time as Fri, 04 Mar 2011 08:47:10
TIME = strftime("%d %b %Y", localtime())
SPACE_LEFT=500000 / 1048576
SPACE_TOTAL = 1000000 / 1048576
if (SPACE_LEFT < LIMIT):
STATUS = "Free Disk Space is ALERT!!!ALERT!!!ALERT!!! "
SPACE_LEFT=SPACE_LEFT / 1024
print ( TIME+"\n"+STATUS+"\n"+str(SPACE_LEFT)+" GB left on disk\n"+"Alert Space is:"+str((LIMIT/1024))+"GB")
subj = "ALERT!!!ALERT!!!ALERT!!!["+str(SPACE_LEFT)+" GB left]Free disk space on wwwcom "+TIME
message_text = TIME+"\n"+STATUS+"\n"+str(SPACE_LEFT)+" GB left on disk\n"+"Alert Space is:"+str((LIMIT/1024))+"GB"
msg = "From: %s\nTo: %s\nSubject: %s\nDate: %s\n\n%s" % ( from_addr, to_addr_alert, subj, TIME, message_text )
smtp.sendmail(from_addr, to_addr_alert, msg)
smtp.sendmail(from_addr, to_addr_alert, msg)
smtp.sendmail(from_addr, to_addr_alert, msg)
smtp.quit()
print ('Done')
elif (SPACE_LEFT > LIMIT):
STATUS = "Free Disk Space is OK on "
SPACE_LEFT=SPACE_LEFT / 1024
SPACE_TOTAL=SPACE_TOTAL / 1024
print ( TIME+"\n"+STATUS+"\n"+str(SPACE_LEFT)+" GB left on disk("+str(SPACE_TOTAL)+"GB)\n"+"Alert Space is:"+str((LIMIT/1024))+"GB")
subj = "["+str(SPACE_LEFT)+" GB left]Free disk space on ww) "+TIME
message_text = TIME+"\n"+STATUS+"\n"+"Total space is :"+str(SPACE_TOTAL)+"GB\n"+str(SPACE_LEFT)+" GB left on disk\n"+"Alert Space is:"+str((LIMIT/1024))+"GB"
msg = "From: %s\nTo: %s\nSubject: %s\nDate: %s\n\n%s" % ( from_addr, to_addr_normal, subj, TIME, message_text )
smtp.sendmail(from_addr, to_addr_normal, msg)
smtp.quit()
print ('Done!')
else:
print ("""
A serius problem detected with the script.
Please check what mount points you monitor and check that they're in the MON_ARRAY aswell.
""" )
python邮件收发SAMPLE的更多相关文章
- Python:sample函数
sample(序列a,n) 功能:从序列a中随机抽取n个元素,并将n个元素生以list形式返回. 例: from random import randint, sample date = [randi ...
- python——random.sample()的用法
写脚本过程中用到了需要随机一段字符串的操作,查了一下资料,对于random.sample的用法,多用于截取列表的指定长度的随机数,但是不会改变列表本身的排序: list = [0,1,2,3,4] r ...
- python参数Sample Code
import time import datetime import getopt import sys try: opts, args = getopt.getopt(sys.argv[1:], & ...
- Python Learning
这是自己之前整理的学习Python的资料,分享出来,希望能给别人一点帮助. Learning Plan Python是什么?- 对Python有基本的认识 版本区别 下载 安装 IDE 文件构造 Py ...
- Python本地化例子 - gettext 模块
关键字:Python 3.4,gettext,本地化,Localization OS:Windows 7,Mac 1. 创建一个locsample.py文件,文件内容如下,把所有需要本地化的字符串放到 ...
- 关于乱序(shuffle)与随机采样(sample)的一点探究
最近一个月的时间,基本上都在加班加点的写业务,在写代码的时候,也遇到了一个有趣的问题,值得记录一下. 简单来说,需求是从一个字典(python dict)中随机选出K个满足条件的key.代码如下(py ...
- 像Excel一样使用python进行数据分析
Excel是数据分析中最常用的工具,本篇文章通过python与excel的功能对比介绍如何使用python通过函数式编程完成excel中的数据处理及分析工作.在Python中pandas库用于数据处理 ...
- Python面向对象编程和模块
在面向对象编程中,你编写表示现实世界中的事物和情景的类,并基于这些类来创建对象. 编写类时,你定义一大类对象都有的通用行为.基于类创建对象时,每个对象都自动具备这种通用行为,然后根据需要赋予每个对象独 ...
- 阿里云收集服务器性能指标的python脚本
#!/usr/bin/python ######################################### # Function: sample linux performance ind ...
随机推荐
- Linux Bash终端支持中文显示
方法:修改系统变量LANG 即时生效: LANG=en_US.UTF- 永久生效: 修改.bashrc,加入 fi
- python+django+wusgi+nginx安装部署
基于centos搭建nginx+uwsgi运行django环境 环境: CentOS 7 nginx/1.9.12 Python 2.7.5 一:安装依赖包5 yum install zlib-dev ...
- uboot之at91sam9g45移植
一.第一阶段,无修改 二.第二阶段 u-boot-1.3.4\lib_arm\board.c 1.增加头文件 2.增加版本号 3.start_armboot中初始化部分 板级初始化部分init_seq ...
- CentOS 6.4安装OpenOffice
终端依次输入: (1)sudo yum install openoffice.org-writer (2) sudo yum install openoffice.org-calc (3) sudo ...
- VS2010配置目录,解决:error MSB6006: “CL.exe”已退出,代码为 5问题
配置属性->VC++目录 可执行文件目录:$(VCInstallDir)bin;$(WindowsSdkDir)bin\NETFX 4.0 Tools;$(WindowsSdkDir)bin;$ ...
- Parameters
Quote from: http://ss64.com/nt/syntax-args.html Parameters A parameter (or argument) is any value pa ...
- 九度OJ 1087 约数的个数
题目地址:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...
- Python:如何得到Popen的输出?
from:http://www.cnblogs.com/bluescorpio/archive/2010/05/04/1727020.html 最近在用subprocess中的Popen做个磁盘监控小 ...
- mysql复制表数据或表结构到新表中
MySQL复制表数据到新表的几个步骤. 1.MySQL复制表结构及数据到新表 CREATE TABLE new_table SELECT * FROM old_table; 2.只复制表结构到新表 C ...
- 深入了解overflow
1.如果overflow-x与overflow-y值不同 其中一个赋值为visiable,另一个赋值scroll/auto/hidden,那么visiable会重置为auto 2.overflow ...