zoukankan      html  css  js  c++  java
  • 阿铭每日一题 day 9 20180119

    DAY9参考答案:ps~=不是唯一的答案

     1 #!/usr/bin/env python
     2 #-*- coding: UTF-8 -*-
     3 import os,sys
     4 reload(sys)
     5 sys.setdefaultencoding('utf8')
     6 import getopt
     7 import smtplib
     8 from email.MIMEText import MIMEText
     9 from email.MIMEMultipart import MIMEMultipart
    10 from  subprocess import *
    11 def sendqqmail(username,password,mailfrom,mailto,subject,content):
    12     gserver = 'smtp.qq.com'
    13     gport = 25
    14     try:
    15         msg = MIMEText(unicode(content).encode('utf-8'))
    16         msg['from'] = mailfrom
    17         msg['to'] = mailto
    18         msg['Reply-To'] = mailfrom
    19         msg['Subject'] = subject
    20         smtp = smtplib.SMTP(gserver, gport)
    21         smtp.set_debuglevel(0)
    22         smtp.ehlo()
    23         smtp.login(username,password)
    24         smtp.sendmail(mailfrom, mailto, msg.as_string())
    25         smtp.close()
    26     except Exception,err:
    27         print "Send mail failed. Error: %s" % err
    28 def main():
    29     to=sys.argv[1]
    30     subject=sys.argv[2]
    31     content=sys.argv[3]
    32 ##定义QQ邮箱的账号和密码,你需要修改成你自己的账号和密码(请不要把真实的用户名和密码放到网上公开,否则你会死的很惨)
    33     sendqqmail('1234567@qq.com','aaaaaaaaaa','1234567@qq.com',to,subject,content)
    34 if __name__ == "__main__":
    35     main()
    36     
    37     
    38 #####脚本使用说明######
    39 #1. 首先定义好脚本中的邮箱账号和密码
    40 #2. 脚本执行命令为:python mail.py 目标邮箱 "邮件主题" "邮件内容"
     1 #!/bin/bash
     2 ip=123.23.11.21
     3 ma=abc@139.com
     4 while 1
     5 do
     6 ping -c10 $ip >/dev/null 2>/dev/null
     7 if [ $? != “0” ];then
     8 python /usr/local/sbin/mail.py $ma “$ip down” “$ip is down”
     9 #假设mail.py已经编写并设置好了
    10 fi
    11 sleep 30
    12 done
  • 相关阅读:
    Kafka架构概述
    Logstash使用进阶篇
    Logstash使用快速入门
    Ubuntu环境部署Logstash实战案例
    Nginx代理Kibana并实现登录认证实战案例
    Ubuntu环境部署Kibana实战案例
    Idea打包JAR包图解
    Wormhole部署实战案例
    编译Wormhole实战篇
    Wormhole的核心概念
  • 原文地址:https://www.cnblogs.com/ivan-yang/p/8323568.html
Copyright © 2011-2022 走看看