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 ...
随机推荐
- 【日常笔记】mybatis 处理 in 语句的使用
在Mybatis的xml配置中使用集合,主要是用到了foreach动态语句. foreach的参数:foreach元素的属性主要有 item,index,collection,open,separat ...
- iOS不得姐项目--TabBar的重复点击实现当前模块刷新;状态栏点击实现当前模块回滚到最顶部
一.实现功能:重复点击tabBar,刷新当前TableView,其余不受影响 <1>实现思路: 错误的方法: TabBar成为自己的代理,监听自己的点击--这种方法是不可取的,如果外面设置 ...
- 【BZOJ 1069】【SCOI 2007】最大土地面积 凸包+旋转卡壳
因为凸壳上对踵点的单调性所以旋转卡壳线性绕一圈就可以啦啦啦--- 先求凸包,然后旋转卡壳记录$sum1$和$sum2$,最后统计答案就可以了 #include<cmath> #includ ...
- Windows Server 2008 R2 每隔一段时间自动关机解决办法
情况描述: “我的电脑-->右键属性”中显示“已激活”,而“管理工具”中显示未激活.系统中有进程wlms.exe. 网上找了下解决方式: 1.提权工具:PSTOOLS(下载地址:http://m ...
- JS跳出框架返回上一页
链接部分 <a class="link" href="javascript:;" target="_top" onclick=&quo ...
- PyQt类库介绍
安装完PyQt后我们去看看这个库里面有些什么cd /usr/lib/python3/dist-packages/PyQt5/ && ls都是些.so的动态链接库,这就是为什么我们在安 ...
- dede使用方法----如何调用最新文章,最热文章,友情链接
dede如何调用最新文章 {dede:arclist row='5' titlelen='50' orderby ='pubdate'} <li><a h ...
- 一次愚蠢的NOIP模拟赛
找礼物[find.pas/find.c/find.cpp] [问题描述] 新年到了,突然间,就在那美丽的一霎那,你好友和你(K个人)的周围满是礼物,你发扬你帅气的风格,让你的好友先拿,但是每个人只能拿 ...
- 【BZOJ-1912】patrol巡逻 树的直径 + DFS(树形DP)
1912: [Apio2010]patrol 巡逻 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 1034 Solved: 562[Submit][St ...
- Linux安装pdo_mysql模块
网站不能访问 查看apache日志 PHP Fatal error: Uncaught exception 'PDOException' with message 'could not find dr ...