@@ -33,7 +33,7 @@ def connect_ssh(host: str) -> tuple[Channel, SSHClient, str]:
3333
3434 channel .send (b"enable\n " )
3535 sleep (0.05 )
36- olt_name = read_output (channel ).splitlines ()[- 1 ].strip ().rstrip ('#' )
36+ olt_name = read_output (channel , False ).splitlines ()[- 1 ].strip ().rstrip ('#' )
3737 clear_buffer (channel )
3838
3939 channel .send (b"config\n " )
@@ -145,7 +145,7 @@ def clear_buffer(channel: Channel):
145145 if channel .recv_ready ():
146146 channel .recv (32768 )
147147
148- def read_output (channel : Channel ):
148+ def read_output (channel : Channel , force : bool = True ):
149149 """Read console output"""
150150 output = ""
151151 last_data_time = time ()
@@ -163,17 +163,18 @@ def read_output(channel: Channel):
163163 continue
164164
165165 # command completed ("user#" input in data)
166- if output .strip ().endswith ('#' ) and len (output .strip ().strip ('\n ' ).splitlines ()) > 5 :
166+ if output .strip ().endswith ('#' ) and ( len (output .strip ().strip ('\n ' ).splitlines ()) > 5 or not force ) :
167167 print ('command completed' )
168168 break
169169 sleep (0.05 )
170170 # if no new data more than 1.5 seconds and output is not empty
171- if time () - last_data_time > 1.5 and len (output .strip ().strip ('\n ' ).splitlines ()) > 5 :
172- print ('no new data more than 1.5 seconds' )
173- break
174- # if no new data more than 8 seconds and output is empty
175- if time () - last_data_time > 8 and len (output .strip ().strip ('\n ' ).splitlines ()) <= 5 :
176- print ('warn: no new data more than 8 seconds' )
171+ # if time() - last_data_time > 1.5 and len(output.strip().strip('\n').splitlines()) > 5:
172+ # print('no new data more than 1.5 seconds')
173+ # break
174+ # if no new data more than 15 seconds and output is empty
175+ if time () - last_data_time > 15 and len (output .strip ().strip ('\n ' ).splitlines ()) <= 4 :
176+ print ('warn: no new data more than 15 seconds' )
177+ print (output )
177178 break
178179 sleep (0.01 )
179180
0 commit comments