Python自动化运维之简易ssh自动登录

#!/usr/bin/env python

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


import pexpect

import sys


ssh = pexpect.spawn('ssh [email protected] ')

fout = file('sshlog.txt', 'w')

ssh.logfile = fout



ssh.expect("[email protected]'s password:")

ssh.sendline("yzg1314520")

ssh.expect('#')

ssh.sendline('ls /home')

ssh.expect('#')


你可能感兴趣的:(python,File,import,password)