0
votes

I am trying to run a command over ssh session. This command is taking more than 1hr. to complete(installing few file sets). Now My script is able to start the command,but,it is failing after few mins,with this below error msg.

File "./return.py", line 32, in CHECKFILESTATUS s.logout() File "/usr/lib/python2.7/site-packages/pexpect-4.2.0-py2.7.egg/pexpect/pxssh.py", line 350, in logout index = self.expect([EOF, "(?i)there are stopped jobs"]) File "/usr/lib/python2.7/site-packages/pexpect-4.2.0-py2.7.egg/pexpect/spawnbase.py", line 321, in expect timeout, searchwindowsize, async) File "/usr/lib/python2.7/site-packages/pexpect-4.2.0-py2.7.egg/pexpect/spawnbase.py", line 345, in expect_list return exp.expect_loop(timeout) File "/usr/lib/python2.7/site-packages/pexpect-4.2.0-py2.7.egg/pexpect/expect.py", line 107, in expect_loop return self.timeout(e) File "/usr/lib/python2.7/site-packages/pexpect-4.2.0-py2.7.egg/pexpect/expect.py", line 70, in timeout raise TIMEOUT(msg) pexpect.exceptions.TIMEOUT: Timeout exceeded. command: /bin/ssh args: ['/bin/ssh', '-q', '-l', 'xxxx', 'sys'] buffer (last 100 chars): 'eement acceptance. You can view the license file details in the /ITM/LAP/license directory\r\n' before (last 100 chars): 'eement acceptance. You can view the license file details in the /ITM/LAP/license directory\r\n' after: match: None match_index: None exitstatus: None flag_eof: False pid: 4289 child_fd: 5 closed: False timeout: 30 delimiter: logfile: None logfile_read: None logfile_send: None maxread: 2000 ignorecase: False searchwindowsize: None delaybeforesend: 0.05 delayafterclose: 0.1 delayafterterminate: 0.1 searcher: searcher_re: 0: EOF 1: re.compile("(?i)there are stopped jobs").

enter code here
#!/bin/python
import pexpect
import netrc
from pexpect import pxssh,TIMEOUT

LPAR = 'VI'
secrets = netrc.netrc()
ID, MC, PD = secrets.authenticators( LPAR )
hostname = raw_input('hostname: ')

def CHECKFILESTATUS(command):
global hostname
global ID
global PD

    try:
        s = pxssh.pxssh()
        hostname = hostname
        username = ID
        password = PD
        s.login(hostname, username, password)
        s.sendline(command)
        s.prompt()
        print s.before
        s.logout()
    except pxssh.ExceptionPxssh, e:
        print("pxssh failed on login.")
        print(e)


def main():
CHECKFILESTATUS('updateios -dev /mnt/V -install -accept')


if __name__ == '__main__':
 main()

Any suggestion to resolve this time-out issue?

1

1 Answers

3
votes

I think

s = pxssh.pxssh(timeout=7200)

Should do the trick

Looking at the source, the pxssh constructor takes timeout as a keyword argument and sets the timeout(I'm guessing in seconds).

def init (self, timeout=30, maxread=2000, searchwindowsize=None, logfile=None, cwd=None, env=None, ignore_sighup=True, echo=True, options={}, encoding=None, codec_errors='strict'):