Note: 1, Pxssh class, exist in the Pexpect module, if you do not install this module installed on its own, if the module already exists, but there is no pxssh class, it is verified that this module version is too low. Please update to the new version #!/usr/bin/env pythonfrom pexpect import pxsshimport os,getpasshosts = Raw_input (' Enter the host address: ') Username = raw_input (' Enter the user name: ') passwd = Getpass.getpass (' Enter the password: ') shell = raw_input (' Type the CO Mmand: ') try:s = Pxssh.pxssh () s.login (hosts,username,passwd) s.sendline (shell) s.prompt () print S.before S.logout () except Pxssh. Exceptionpxssh, E:print "Pxssh failed on login" Print str (e)
This article is from the "Fa&it-Q Group: 223843163" blog, please be sure to keep this source http://freshair.blog.51cto.com/8272891/1873423
Python's pxssh "big change" makes it an interactive applet