网站首页 首页
第一次用PYTHON写脚本.........
发布时间:2017-10-31 04:54查看次数:3364
第一次用PYTHON写脚本.........
临时抱佛脚啊! 应用场景 几千台手机系统需要做垃圾清理动作...............升级动作
用winscp脚本 灵活性不够 sct的脚本不会
百度一下 派森脚本 好牛逼 各种模块很成熟!简单暴力
说说第一次写踩的坑..........就是这个换行符 派森对换行符要求很严格
犹豫不清楚规则 直接用空格 各种错误啊! 搞死搞残废
这些写给第一次用 派森的苦逼猴子
第二个坑 就是中文乱码 这个要在脚本头部 叫codeing 编码标识符
最后引入多线程
脚本如下:
#!/usr/bin/python
#-*-coding:gbk
import paramiko
import threading
import time
def ssh2(ip):
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip, username='root', password='alpine')
print "发送删除命令-开始"
temp_time = time.time()
stdin,stdout,stderr=ssh.exec_command('*********************')
print stdout.read()
temp_time_2 = time.time()
print "发送删除命令-结束" + str(temp_time_2 - temp_time)
print "发送优化命令"
stdin,stdout,stderr=ssh.exec_command('rm -rf /private***********/*')
print stdout.read()
stdin,stdout,stderr=ssh.exec_command('rm -rf /var/mobil************s/*')
print stdout.read()
stdin,stdout,stderr=ssh.exec_command('sh /private/v**************.postrm')
print stdout.read()
stdin,stdout,stderr=ssh.exec_command('killallP')
print stdout.read()
stdin,stdout,stderr=ssh.exec_command('killall -9 SpringBoard')
print stdout.read()
print "发送跳转命令"
stdin,stdout,stderr=ssh.exec_command('cd /private/var/root')
stdin,stdout,stderr=ssh.exec_command('ls')
print stdout.read()
print ip + "完成操作!"
except Exception, e:
print "错误:"+ip
if __name__=='__main__':
ip='12.10.1.'
hostname = ip
username = 'root'
password = 'alpine'
for x in xrange(60,70):
temp = ip + str(x)
print "ip:"+temp
a = threading.Thread(target=ssh2,args=[temp])
a.start()关键字词:javascript##