python多线程运维脚本
2015-01-24 14:37
316 查看
需求,有一个IP列表文件 ip.txt,里面有1000个ip,那么我要用python同时来处理这1000个IP。
先看ip.txt
192.168.1.1
192.168.1.2
192.168.1.3
......
192.168.1.1000
多线程并发脚本
先看ip.txt
192.168.1.1
192.168.1.2
192.168.1.3
......
192.168.1.1000
多线程并发脚本
#!/usr/bin/python import threading import sys import os import time def ssh_cmd(ip): //定义一个ssh_cmd函数 用于发呆5秒,输出ip time.sleep(5) print ip def ssh_cmd_spit(list): //定义一个ssh_cmd_spit函数,用于执行分割后的ip列表 for j in list: j = j.strip("\n") ssh_cmd(j) def thread_main(count): //定义一个thread_main函数,用于设置每个进程处理的IP个数,设置为1,那么1000个IP需要同时开1000个线程,设置为50,那么需要20个线程来同时处理。 file = open("ip.txt") f = file.readlines() for i in range(0,len(f),int(count)): b = f[i:i+count] t = threading.Thread(target=ssh_cmd_spit,args=(b,)) //添加线程 t.start() //处理线程 if __name__ == '__main__': thread_main(1)
相关文章推荐
- python脚本监控网站状态 - 赵海华_运维之路 - 51CTO技术博客
- Python多线程自动刷票脚本
- 【Python运维脚本】Python监控网卡流量
- 【Python运维脚本】Python监控CPU情况
- 【Python运维脚本】Python监控系统负载
- 几个python运维脚本
- python多线程http压力测试脚本
- 【Python运维脚本】Python监控CPU情况
- 【Python运维脚本】Python监控磁盘
- rsync多线程备份脚本 --python
- 几个python运维脚本
- 【Python运维脚本】生成随机密码
- 【Python运维脚本】生成随机密码
- 【Python运维脚本】Python监控系统负载
- 【Python运维脚本】Python监控内存(swap)的使用率
- python 运维脚本利器-- pexpect
- 【Python运维脚本】查看各个进程读写的磁盘IO
- 【Python运维脚本】Python监控内存(swap)的使用率
- 【Python运维脚本】Python监控网卡流量
- python 多线程脚本