python的简洁是shell无法代替的
之前线上服务器分发配置都是用shell和expect脚本分发,脚本写了很长,上周换了ansible,现在自己用python写一个,就30行代码就可以实现需求,之前的shell写了快200行了,蛋疼,代码如下:
from multiprocessing import Process
import paramiko
import sys
file = sys.argv[1]
Username = "root"
Password = "123456"
Dest_Path = [ "/data/x5online/%s" %file,
"/tmp/%s" %file ]
Port = 22
def sftpPut(ip):
try:
s = paramiko.Transport((ip,Port))
s.connect(username=Username,password=Password)
sftp = paramiko.SFTPClient.from_transport(s)
localFile = file
for remoteFile in Dest_Path: sftp.put(localFile,remoteFile)
print("%s put successful." %ip)
except:
print("%s not exits."%ip)
def ipProcess():
for i in range(10,40):
ip = '192.168.170.%s'%i
p = Process(target=sftpPut,args=(ip,))
p.start()
if __name__ == '__main__':
ipProcess()
鸡汤一回,对python感兴趣了,学的才快。
python的简洁是shell无法代替的的更多相关文章
- Python第一天 安装 shell 文件
Python第一天 安装 shell 文件 python里面一切都是对象 object 代码缩进:建议用四个空格来缩进,不要用tab键 安装 Linux自带python,windows需要下载m ...
- python 之调用Linux shell命令及相关高级应用
最近根据老大要求,将数据进行同步备份,结合第三方提供的工具.第三方服务其实是有python demo的,本想研究下实际的python sdk搞个demo开发的,但是发现有些组建装起来确实头大,而且本公 ...
- shell如何向python传递参数,shell如何接受python的返回值
1.shell如何向python传递参数 shell脚本 python $sendmailCommandPath $optDate python脚本 lastDateFormat = sys.argv ...
- Python爬虫教程-33-scrapy shell 的使用
本篇详细介绍 scrapy shell 的使用,也介绍了使用 xpath 进行精确查找 Python爬虫教程-33-scrapy shell 的使用 scrapy shell 的使用 条件:我们需要先 ...
- python调用脚本或shell的方式
python调用脚本或shell有下面三种方式: os.system()特点:(1)可以调用脚本.(2)可以判断是否正确执行.(3)满足不了标准输出 && 错误 commands模块特 ...
- jenkins服务器使用python脚本rabbitmqadmin和shell对目标服务器进行管理
jenkins服务器使用python脚本rabbitmqadmin和shell对目标服务器进行管理 准备工作: .jenkins服务器,安装rabbitmqadmi命令 rabbitmqadmin管理 ...
- python执行linux的shell命令
python执行shell脚本常用的方法 import os val=os.system("shell语句") >>> val=os.system(" ...
- python最简洁的条件判断语句写法
这篇文章主要介绍了Python返回真假值(True or False)小技巧,本文探讨的是最简洁的条件判断语句写法,本文给出了两种简洁写法,需要的朋友可以参考下 如下一段代码: def isLen(s ...
- 用python -i写交互式shell
cabinet是公司的一个数据存储服务,需要添加一个shell client,查看数据,做简单操作. 用python写了一个比想象的简单.代码如下: #! /usr/bin/python -i # c ...
随机推荐
- extjs 箱子布局
a.flex 配置项 flex 配置项不是设置在布局上,而是设置在子项的配置项.每个子项相对的 flex 值都会与全体子项 flex 累加的值相比较,根据此结果,处理每个子项的 flex 最后是多少. ...
- 纯CSS下拉导航菜单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="h ...
- jsrender for object
<div id="result"></div> <script id="theTmpl" type="text/x-js ...
- 进程间通信方式与Binder机制原理
1, Intent隐式意图携带数据 2, AIDL(Binder) 3, 广播BroadCast 4, 内容提供者ContentProvider --------------------------- ...
- 【POJ 1679】The Unique MST(次小生成树)
找出最小生成树,同时用Max[i][j]记录i到j的唯一路径上最大边权.然后用不在最小生成树里的边i-j来替换,看看是否差值为0. #include <algorithm> #includ ...
- python面向对象
1.概念 类:(class):具有相同属性和方法的对象的集合.用来定义该集合中每个对象所共有的属性和方法.对象是类的实例. 方法:类中定义的函数. 实例化:创建一个类的实例,类的具体对象. 对象:通过 ...
- sql中的xml使用
SQL openxml用法 使用sp_xml_preparedocument处理XML文档(原文:http://www.cnblogs.com/oec2003/archive/2011/07/23/2 ...
- Servlet教程
有JSP的教程,就有Servlet教程. http://www.runoob.com/servlet/servlet-tutorial.html
- 虚拟机:Python虚拟机的基本了解
探索某个东西,我们需要知道这个东西是用来干什么的,能给我们带来什么,解决了什么样的问题,有什么优缺点等等:简要了解了一下Python虚拟机的特征: 目前有几个疑问: 1.对象 · Python通过对象 ...
- libusb-win32简介~
libusb-win32简介 libusb-win32 is a port of the USB library libusb (http://sf.net/projects/libusb/) to ...