By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,285 Members | 1,691 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,285 IT Pros & Developers. It's quick & easy.

Not able to print the variable in which popen result of a remote m/c is stored.

P: 1
Expand|Select|Wrap|Line Numbers
  1. port2_result=os.popen('ipmitool raw 0x3a 0x11 0x2a 0x6f 0x00 8').read()
this is the expression i've written in a script after calling a procedure to establish SSH connection to a remote machine. the same thing works for local machine but after ssh, it's giving the variable as '[ ]'. the ssh procedure is as follows:
Expand|Select|Wrap|Line Numbers
  1. def SSH (user,host,PROMPT) :
  2.     os.system('rm -f /root/.ssh/known_hosts')
  3.     SSHd = 'ssh '+user+'@'+host
  4.     ssh_obj = pexpect.spawn(SSHd)
  5.     try :
  6.         ssh_obj.logfile=None;
  7.         ssh_obj.expect('\(yes\/no\)\?',timeout=50)
  8.         ssh_obj.sendline('yes')
  9.     except :
  10.         print "Unable to login to "+host
  11.         sys.exit(3)
  12.     try:
  13.         ssh_obj.expect(PROMPT,timeout=50)
  14.     except:
  15.         print "Unable to login to "+host
  16.         sys.exit(3)
  17.     try:
  18.         ssh_obj.sendline('XYZ')
  19.         ssh_obj.expect('found',timeout=10)
  20.         ssh_obj.sendline('PS1="RTM_SHOW>"')
  21.         ret=ssh_obj.expect(['RTM_SHOW>','#'],timeout=5)
  22.         if ret == 1:
  23.             ssh_obj.expect('RTM_SHOW>',timeout=5)
  24.     except:
  25.         print "Unable to change Prompt"
  26.         sys.exit(3)
  27.     ssh_obj.logfile=sys.stdout;
  28.     return ssh_obj
  29.  
and this is where i'm executing the command
Expand|Select|Wrap|Line Numbers
  1. if node != host :
  2.     print "YES",
  3.     try:
  4.         local=SSH("root",node,'#')
  5.         local.logfile=sys.stdout
  6.     except:
  7.         print "unable to do SSH."
  8.  
  9.  
  10.     try:
  11.               # reg=re.compile(r'^\s\d.+')
  12.                reg=re.compile('.*')
  13.                print "cmdsend"
  14.                local.sendline('ipmitool raw 0x3a 0x11 0x2a 0x6f 0x00 7')
  15.                ret=local.expect([reg,'RTM_SHOW>'],timeout=15)
  16.                if ret == 0:
  17.                    port1_result=local.match.group()
  18.                    print "my",port1_result
  19.                else:
  20.                         sys.exit(1)
  21.  
  22.  
  23.                port2_result = os.popen('ipmitool raw 0x3a 0x11 0x2a 0x6f 0x00 8').read()
  24.                parse_output(port1_result,port2_result)
  25.     except:
  26.                print "error EXECUTING ssh commands."
  27.  
its printing "error EXECUTING ssh commands." the ret value is 0. I don't know how to check what is it actually printing on that remote machine!! pls help!
Jan 22 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.