脚本语言目前发展很快,python流行度也越来越大,对我而言,脚本语言主要作为系统的粘合剂,一般不做主体业务逻辑的开发,但作为系统管理,整合程序还是不错的。所以,今天开始学习python,有点懒,因为有个小需求:linux下SSH远程登录后,发送短信通知管理员。原来一般使用shell直接完成,今天学习python,就作为第一个hello world试试。花了尽2个小时,完全根据程序逻辑需求通过google查语法(怎么定义程序,if,字符串处理等,哈哈),终于完成。记录下咱的first python程序哈。
#!/usr/bin/python import time import base64 import urllib import httplib import os import sys mobileNos=138xxxxxxxx def sendSms(mobileNo,content): url = "/api/......" queryString=urllib.urlencode({"mobileNo": mobileNo, "content": content, "username":"aaaaa", "password":"xxxxxx"}) conn = httplib.HTTPConnection("192.168.xxx,xxx") conn.request("GET",url+"?"+queryString) response = conn.getresponse() conn.close() def logger(log): f=open('lm.log','a+') print >> f, log f.close() def loginNotify(): client = os.getenv("SSH_CLIENT") if client is None: return clientInfo = client.split(' ') ip = clientInfo[0] now = time.strftime('%Y-%m-%d %H:%M:%S') user = os.getenv("USER") hostname = os.getenv("HOSTNAME") log = now + " - " + user + " login " + hostname + " from " + ip logger(log) sendSms(mobileNos,log) if __name__ == "__main__": loginNotify()
相关推荐
分享Head First Python-完整中文版书籍,供大家学习、参考和交流。
《Head First Python(中文版)》超越枯燥的语法和甩法手册,通过一种独特的方法教你学习这种语言。你会迅速掌握Python的基础知识,然后转向持久存储、异常处理、Web开发、SQLite、数据加工和lGoogle App Engine。你还...
Head First Python, 2nd Edition.zip.001 Head First Python, 2nd Edition.zip.001 Head First Python, 2nd Edition.zip.001 Head First Python, 2nd Edition.zip.001 Head First Python, 2nd Edition.zip.001 Head ...
Head First Python(中文版)面向Python3
Python-Web自测试卷4全文共2页,当前为第1页。Python-Web自测试卷4全文共2页,当前为第1页。自测试卷4 Python-Web自测试卷4全文共2页,当前为第1页。 Python-Web自测试卷4全文共2页,当前为第1页。 一、选择题 1....
Head-First-Python-2:书中的练习
一本Python的入门书,三天搞定Python,内附常用代码,对于初学者很有帮助,里面的内容需要用Markdown viewer来打开
Title: Head First Python, 3rd Edition Author(s): Paul Barry Release date: August 2023 Publisher(s): O'Reilly Media, Inc. If you've read a Head First book, you know what to expect: a visually rich ...
dddHead First Python, 2nd Edition.zip.002Head First Python, 2nd Edition.zip.002Head First Python, 2nd Edition.zip.002Head First Python, 2nd Edition.zip.002Head First Python, 2nd Edition.zip.002Head ...
Head First Python A Brain-Friendly Guide, 2nd Edition
Head First Python(第四章)支持文档 Head First Python(第四章)支持文档
Learn quickly and have some fun at the same time with Head First Python. This book takes you beyond typical how-to manuals with engaging images, puzzles, stories, and quizzes that are proven to ...
Learn quickly and have some fun at the same time with Head First Python. This book takes you beyond typical how-to manuals with engaging images, puzzles, stories, and quizzes that are proven to ...
Fundamentals of Python - From First Programs through Data Structures 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 ...
Head First C# -- Third Edition by Andrew Stellman and Jennifer Greene Copyright © 2013 Andrew Stellman and Jennifer Greene. All rights reserved.
Head First系列丛书,Head First Python 3高清扫描PDF文档。
Head First Python 实例代码
名称解析器 一个简单的Python(3.2+和2.6+)模块,用于将人名解析为它们的各个组成部分。 标题首先中间最后一次后缀昵称hn.surnames (姓氏+姓氏)支持的名称结构支持的名称结构通常是“标题第一中间最后一个后缀”...
Head First Python(2nd Edition)[美]Paul Barry【高清版】, PDF格式