Python在linux服务器上解压,python3传文件到linux服务器然后解压

news/2024/7/3 17:02:27

运维开发网 https://www.qedev.com

2020-07-09 10:40

出处:网络作者:运维开发网整理

#!/usr/bin/env python

# -*- coding:utf-8 -*-

import os

import paramiko

import time

from scp import SCPClient

相关专题:#!/usr/bin/env python

# -*- coding:utf-8 -*-

import os

import paramiko

import time

from scp import SCPClient

#将脚本传到服务器,并解压

def transRemote(ip,user,password):

try:

ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect(ip, 22, username=user, password=password, timeout=200)

stdin, stdout, stderr=ssh.exec_command("pwd")

#path=stdout.read().strip("\n")

# 获取路劲

path= stdout.read().decode('utf-8').strip("\n")

#查看python版本

stdin, stdout, stderr=ssh.exec_command("python -V")

print(stdout.read().decode('utf-8'))

# pythonVsersion=stdout.read().strip("\n")

pythonVsersion = stdout.read().decode('utf-8').strip("\n")

scriptName="jixianjiancha.tar.gz"

if(len(pythonVsersion)==0):

scriptName="jixianjiancha.tar.gz"

else:

if(pythonVsersion.split()[1].startswith("3")):

scriptName="jixianjiancha2.tar.gz"

current_path=os.getcwd()

#print current_path

scpclient = SCPClient(ssh.get_transport(), socket_timeout=15.0)

scpclient.put('%s\\check\\%s'%(current_path,scriptName), '%s/jixianjiancha.tar.gz'%path)

print("[*]将脚本传送到远程服务器")

index=0

script_number=12

while(index<10):

stdin, stdout, stderr=ssh.exec_command('tar -xvf %s/jixianjiancha.tar.gz'%path)

time.sleep(2)

stdin, stdout, stderr=ssh.exec_command("ls %s"%(path))

scripts=len(stdout.read().decode('utf-8').strip("\n"))

if(scripts==12):

index=11

else:

index+=1

print("[*]在远程服务器上解压脚本")

ssh.close()

return True

except Exception as e:

print(e)

return False

if __name__ == '__main__':

transRemote('192.168.221.133','root','toor')

分享到

0

0

0


http://lihuaxi.xjx100.cn/news/242402.html

相关文章

Python 第三方库自动安装脚本

需求&#xff1a;批量安装第三方库需要人工干预&#xff0c;能否自动安装&#xff1f; 现假设我们要安装以下库 #BatchInstall.py import os libs {"numpy","matplotlib","pillow","sklearn","requests",\ "jie…

UI设计培训分享:设计当中的颜色运用

参加UI设计培训的同学应该都知道&#xff0c;颜色的搭配是学习UI设计非常重要的一步&#xff0c;颜色跟其他的东西一样&#xff0c;适量才会运用得当&#xff0c;如果在你的配色计划中坚持使用马克思三原色的话&#xff0c;你会得到更好的配色结果&#xff0c;为一个项目配色时…

Cross-validation

2019独角兽企业重金招聘Python工程师标准>>> 1: Introduction To Validation So far, weve been evaluating accuracy of trained models on the data the model was trained on. While this is an essential first step, this doesnt tell us much about how well …

linux设置终端颜色256,如何设置我的Linux X终端以便Emacs可以访问256种颜色?

根据this,除了将TERM设置为xterm-256color之外,还需要ncurses-term库.好的,this还有其他一些尝试&#xff1a;The xterm in Ubuntu Edgy does not advertise 256 color support bydefault. To fix this you need to install a 256 color terminfo entry,and tell xterm to use …

Linux下使用mv重命名文件或者移动文件(增强版的工具为rename)

mv命令既可以重命名&#xff0c;又可以移动文件或文件夹。 例子&#xff1a;将目录A重命名为B mv A B 例子&#xff1a;将/a目录移动到/b下&#xff0c;并重命名为c mv /a /b/c 例子&#xff1a;将文件A.txt重命名为B.txt mv A.txt B.txt 例子&#xff1a;将文件A.txt移动到B目…

CSP 2019-09-1 小明种苹果 Python实现+详解

试题 代码 # N,M分别表示树的棵树和疏果轮数 N,M [int(i) for i in input().split()]leftTrees 0#最后所有树树上的苹果总数 reduceMaxIndex 0#疏果个数最多的苹果编号 reduceMaxSum 0#上面那棵树的个数reduceMaxSum 0 reduceMaxIndex 0 leftTrees 0 for i in range(N)…

UI设计培训分享:UI设计师的设计思路

想要成为一名合格的UI设计师&#xff0c;那么设计思路是非常重要的&#xff0c;今天小编为大家带来的UI设计培训课程就是关于“UI设计师的设计思路“&#xff0c;不管你是已经从事UI行业了还是刚刚准备从事UI行业&#xff0c;都离不开三点“看、想、做”。今天的这篇文章&#…

linux 查看域名解析,linux查询服务器域名解析记录

弹性云服务器 ECS弹性云服务器(Elastic Cloud Server)是一种可随时自助获取、可弹性伸缩的云服务器&#xff0c;帮助用户打造可靠、安全、灵活、高效的应用环境&#xff0c;确保服务持久稳定运行&#xff0c;提升运维效率三年低至5折&#xff0c;多种配置可选了解详情什么是弹性…