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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • George Bush
    New Member
    • Jan 2011
    • 1

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

    Code:
    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:
    Code:
    def SSH (user,host,PROMPT) :
        os.system('rm -f /root/.ssh/known_hosts')
        SSHd = 'ssh '+user+'@'+host
        ssh_obj = pexpect.spawn(SSHd)
        try :
            ssh_obj.logfile=None;
            ssh_obj.expect('\(yes\/no\)\?',timeout=50)
            ssh_obj.sendline('yes')
        except :
            print "Unable to login to "+host
            sys.exit(3)
        try:
            ssh_obj.expect(PROMPT,timeout=50)
        except:
            print "Unable to login to "+host
            sys.exit(3)
        try:
            ssh_obj.sendline('XYZ')
            ssh_obj.expect('found',timeout=10)
            ssh_obj.sendline('PS1="RTM_SHOW>"')
            ret=ssh_obj.expect(['RTM_SHOW>','#'],timeout=5)
            if ret == 1:
                ssh_obj.expect('RTM_SHOW>',timeout=5)
        except:
            print "Unable to change Prompt"
            sys.exit(3)
        ssh_obj.logfile=sys.stdout;
        return ssh_obj
    and this is where i'm executing the command
    Code:
    if node != host :
        print "YES",
        try:
            local=SSH("root",node,'#')
            local.logfile=sys.stdout
        except:
            print "unable to do SSH."
    
    
        try:
                  # reg=re.compile(r'^\s\d.+')
                   reg=re.compile('.*')
                   print "cmdsend"
                   local.sendline('ipmitool raw 0x3a 0x11 0x2a 0x6f 0x00 7')
                   ret=local.expect([reg,'RTM_SHOW>'],timeout=15)
                   if ret == 0:
                       port1_result=local.match.group()
                       print "my",port1_result
                   else:
                            sys.exit(1)
    
    
                   port2_result = os.popen('ipmitool raw 0x3a 0x11 0x2a 0x6f 0x00 8').read()
                   parse_output(port1_result,port2_result)
        except:
                   print "error EXECUTING ssh commands."
    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!
Working...