实现堡垒机模式下的远程文件上传

摘要:[root@node110 paramiko]# cat simple4.py #!/usr/bin/env pythonimport paramikoimport os,sys,timehostname="192.168.2.121"username="root"password="123456"blip="192.168.2.120"bluser="root"blpasswd="123456"tmpdir="/tmp"remotedir="/data"localpath="/home/nginx_access.

 实现堡垒机模式下的远程命令执行

摘要:[root@node110 paramiko]# cat simple3.py #!/usr/bin/env pythonimport paramikoimport os,sys,timehostname="192.168.2.121"username="root"password="123456"blip="192.168.2.120"bluser="root"blpasswd="123456"port=22passinfo='\'s password: 'paramiko.util.log_to_file('syslogin.log')ssh=paramiko

 通过密钥方式登录远程主机

摘要:[root@node110 paramiko]# cat simple2.py #!/usr/bin/env pythonimport paramikoimport oshostname='192.168.2.120'username='root'paramiko.util.log_to_file('syslogin.log')ssh=paramiko.SSHClient()ssh.load_system_host_keys()#privatekey = os.path.expanduser('/home/key/id_rsa')privatekey = os.path.expanduser('/root/.ssh/id_rsa')key = paramiko.RSAKey.fro

 SFTPclient

摘要:#!/usr/bin/env pythonimport paramikousername="root"password="123456"hostname="192.168.2.120"port=22try:    t=paramiko.Transport((hostname,port))    t.connect(username=username,password=password)    sftp=paramiko.SFTPClient.from_transport(t)    sftp.put("/root/test.sql",

 登录远程SSH并返回执行结果SSHClient

摘要:[root@node110 paramiko]# cat simple1.py #!/usr/bin/env pythonimport paramikohostname='192.168.2.120'username='root'password='123456'paramiko.util.log_to_file('syslogin.log')ssh=paramiko.SSHClient()ssh.load_system_host_keys()ssh.connect(hostname=hostname,username=username,password=password)stdin,stdout,stderr=ssh.exec_command('free -m')print st

 pxssh

摘要:[root@node110 pexpect]# cat simple1-pxssh.py import pxsshimport getpasstry:    s = pxssh.pxssh()    hostname = raw_input('hostname: ')    username = raw_input('username: ')    password = getpass.getpass('password: ')    s.login (hostname, username, password)    s.sendline ('uptime') &

 before_after

摘要:[root@node110 pexpect]# cat simple9_before_after.py #1/usr/bin/env pythonimport pexpectimport syschild = pexpect.spawn('ssh root@192.168.198.121')fout = file('mylog.txt','w')child.logfile = foutchild.expect(["password:"])child.sendline("123456")print "before:"+child.beforeprint "after:"+child.after

 ssh自动登录

摘要:[root@node110 pexpect]# cat simple8_ssh_auto_login.py #!/usr/bin/env pythonimport pexpectimport syschild = pexpect.spawn('ssh root@192.168.198.121')fout = file('mylog.txt','w')child.logfile=foutchild.expect("password:")child.sendline("123456")child.expect("#")child.sendline("ls /home")child.expect("

 日志输出到终端

摘要:[root@node110 pexpect]# cat simple7-output-sys_stdout.py #!/usr/bin/env pythonimport pexpectimport sysshell_cmd='ls -l'child = pexpect.spawn('/bin/bash',['-c',shell_cmd])child.logfile=sys.stdoutchild.expect(pexpect.EOF)

 日志输出到文件

摘要:[root@node110 pexpect]# cat simple6-output-logfile.py #!/usr/bin/env pythonimport pexpectimport sysshell_cmd='ls -l'child = pexpect.spawn('/bin/bash',['-c',shell_cmd])fout = file('mylog.txt','w')child.logfile=fout#child.logfile=sys.stdoutchild.expect(pexpect.EOF)
分页:« 1 2 3 4 5 6 7 8 »
Powered by AKCMS