Here is my code:
Some code unnecessary and snipped for this question...
Expand|Select|Wrap|Line Numbers
- def DoStuff():
- fout = file(LOG_FILENAME,'w')
- <snip>
- child = pexpect.spawn('ssh -l root %s'%(i))
- k = child.expect (['connecting (yes/no)', '[Pp]assword: '])
- if k==0:
- print "Adding key for %s"%(i)
- child.sendline ("yes")
- child.expect ('[Pp]assword: ')
- child.sendline (Passwd1)
- if k==1:
- child.sendline (Passwd1)
- l = child.expect (['please try again.', '[#/$]'])
- if l==0:
- child.sendline (Passwd2)
- if l==1:
- child.sendline ('echo')
- child.expect ('[#/$]')
- child.sendline (cmnd)
- child.logfile_read = fout
- child.expect ('#')
- child.logfile = None
- child.sendline ('exit')
I can not figure out why the above, using uptime as the command, gives the following:
Expand|Select|Wrap|Line Numbers
- $ more /tmp/menu2.log
- root@server1 :#uptime
- root@server2 :#uptimeuptime
- 2:53pm up 174 day(s), 8:07, 1 user, load average: 0.00, 0.00, 0.01
- # uptime
- 2:46pm up 174 day(s), 7:53, 1 user, load average: 0.04, 0.04, 0.04
- #
- root@server3 :#uptime
- root@server4 :#uptime
- root@server5 :#uptime.example.com now...