SSH python script execution taking too much time -


i using python script ssh , connect 2 pc's running iperf commands, script taking lot of time execution. how can reduce execution time: script being run eclipse ide.

this script using:

import pexpect import pxssh import time import os,re,sys    def tc01s(ipaddr,password): try:      ss = pexpect.spawn(ipaddr)     print ipaddr             ss.logfile = open("/tmp/mynewlog", "w")         #ss.logfile = sys.stdout         print "ssh connecting"         print  except:     print "connection refused"     print     #sys.exit()      try:         print password     ss.expect (':')           ss.sendline (password +"\n")         print "connected"         time.sleep(30)         ss.expect (">")         print "connection established"         print     except:         print "permission denied, please try again."         print         sys.exit()     try:         ss.sendline ('taskkill /f /im iperf.exe\n')         #time.sleep(30)         ss.expect ('>')         #os.system("d:\iperf-2.0.5-2-win32\iperf.exe -s\n")         ss.sendline ('cd /d d:\iperf-2.0.5-2-win32')         ss.expect ('>')         ss.sendline ('iperf -s -u -f m -p 5000 -l 1470 -i 1')         ss.expect (r'tcp window size: .*yte \(default\)')         time.sleep(30)                     except:          print          print         #sys.exit()   ############################################################################### time.sleep(30) def tc01c(ipaddr,password):  try:     css = pexpect.spawn(ipaddr)     css.logfile = open("/tmp/mynewlog", "w")     #css.logfile = (sys.stdout)     print "ssh connecting"     print except:     print "connection refused"     print     sys.exit() try:     css.expect (':')     css.sendline (password + "\n")     print "connected"     time.sleep(30)     css.expect (">")     print "connection established"     print except:     print "permission denied, please try again."     print     sys.exit() try:     #css.sendline ('taskkill /f /im iperf.exe\n')     print css.logfile     css.expect ('>')     css.sendline ('d:' + "\r")     #css.sendline ('cd /d d:\iperf-2.0.5-2-win32')     css.expect ('>')     css.sendline ('dir' + "\r")     css.sendline ('cd iperf ' + "\r")     css.expect ('>')     css.sendline ('iperf -u -f m -c 192.168.100.101 -p 5000 -b 3.00m -t 10 -l 1470 -i 1 \r\n')     css.expect (r'tcp window size: .*yte \(default\)')               time.sleep(30)   except:      print      print     #sys.exit()   ############################################### above code executed using  import os import pexpect import ssh import time  ssh.tc01s("ssh user@192.168.100.101","pass123") ssh.tc01c("ssh domain@192.168.100.85","123pass")     

as commenters mentioned, without code hard answer. in case don't want/can't attach code here, have guesses:

  • if you're running executable ssh client, try switching library.
  • maybe specific commands you're running what's slow, , not connection itself? try running else (simpler) know sure ssh connection what's slow.
  • other wild guesses of things might slow down: network slow, receiving ends busy, host busy, etc.

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -