python连接linux

#!/usr/local/bin/python
#-*- coding: UTF-8 -*-
import paramiko
import os
ip="192.168.1.1"
port=22
user="root"
password="1111"
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
    ssh.connect(ip,port,user,password,timeout=5)
    cmd=""
    while True:
        inputs=raw_input("[root@localhost ~]#") 
        if cmd=="":
            cmd=inputs
        else:
            cmd=cmd+";"+inputs
        #print cmd.find("ls")

        if cmd.find("ls")>=0:

            stdin,stdout,stderr=ssh.exec_command(cmd)

            out=stdout.readlines()
            for o in out:
                print o
            cmd=""
    ssh.close()
except Exception,e:
    print e

你可能感兴趣的:(python连接linux)