def doSSHPT(self, hosts, username, password, command): """The results page""" # Give ourselves an output queue to save results into results_queue = Queue.Queue() commands = [command,] # Has to be a list sshpt.sshpt(hostlist=hosts, username=username, password=password, commands=commands, output_queue=results_queue) page = "<html><head><title>SSHPT Via Web Example</title></head><body>" # Print a table header page += "<table border='1'><tr><td><b>Host</b></td><td><b>Command</b></td><td><b>Command Output</b></td></tr>" for host in results_queue.queue: page += "<tr>" page += "<td>%s</td>" % host['host'] page += "<td>%s</td>" % "".join(host['commands']) page += "<td><pre>%s</pre></td>" % "".join(host['command_output']) page += "</tr>" page += "</table>" page += "</body></html>" return page
# Import the module du jour import sshpt # Obtain the basic information necessary to use sshpt hostlist = raw_input("Host(s) (use spaces for multiple): ").split(" ") username = raw_input("Username: "******"Password: "******"Command: ") commands = [command] # 'commands' has to be a list # Give ourselves an output queue to store results results_queue = Queue.Queue() sshpt.sshpt(hostlist, username, password, commands=commands, output_queue=results_queue) # This is the simplest way of grabbing the data that sshpt returns. The other way would be to write your own version of the OutputThread for host in results_queue.queue: print "host: %s" % host["host"] print "command_output: %s" % host["command_output"] print "commands: %s" % host["commands"] # ...and here's the rest of what you can use # print "username: %s" % host['username'] # print "password: %s" % host['password'] # Do you REALLY this output to the console? # print "timeout: %s" % host['timeout'] # print "local_filepath: %s" % host['local_filepath'] # print "remote_filepath: %s" % host['remote_filepath'] # print "execute: %s" % host['execute'] # print "remove: %s" % host['remove'] # print "sudo: %s" % host['sudo']
# Obtain the basic information necessary to use sshpt hostlist = raw_input('Host(s) (use spaces for multiple): ').split(' ') username = raw_input('Username: '******'Password: '******'Command: ') commands = [ command, ] # 'commands' has to be a list # Give ourselves an output queue to store results results_queue = Queue.Queue() sshpt.sshpt(hostlist, username, password, commands=commands, output_queue=results_queue) # This is the simplest way of grabbing the data that sshpt returns. The other way would be to write your own version of the OutputThread for host in results_queue.queue: print "host: %s" % host['host'] print "command_output: %s" % host['command_output'] print "commands: %s" % host['commands'] # ...and here's the rest of what you can use #print "username: %s" % host['username'] #print "password: %s" % host['password'] # Do you REALLY this output to the console? #print "timeout: %s" % host['timeout'] #print "local_filepath: %s" % host['local_filepath'] #print "remote_filepath: %s" % host['remote_filepath'] #print "execute: %s" % host['execute']