Hello Team,
I am trying to ssh to linux terminal server (Production Server) , and i am facing problem with it
i am writing python code , same code iam using on linux VM and its successful
i am suspecting the the prompt of the server is the one making the problem as it like @ #
i tried with prompt_recovery = True , still the same
code as follows
from unicon import Connection
server = Connection(hostname='',
start=['ssh -q -o LogLevel=error '],
os='linux',
credentials={'default': {'username': '', 'password': ''}},
learn_hostname = True,
debug = True,
)
server.connect()
output = server.execute('date')
print(output)
Log File
(env) myuser@testVM:/var/www/test$ python connectNet.py
2023-02-17 14:03:53,554: %UNICON-INFO: +++ logfile /tmp/-20230217T140353554.log +++
2023-02-17 14:03:53,554: %UNICON-INFO: +++ Unicon plugin linux (unicon.plugins.linux) +++
2023-02-17 14:03:53,554: %UNICON-DEBUG: +++ initializing context +++
2023-02-17 14:03:53,555: %UNICON-DEBUG: +++ initializing state_machine +++
2023-02-17 14:03:53,555: %UNICON-DEBUG: +++ initializing services +++
2023-02-17 14:03:53,555: %UNICON-DEBUG: adding service send : <unicon.plugins.generic.service_implementation.Send object at 0x7fd8e9b08cd0>
2023-02-17 14:03:53,555: %UNICON-DEBUG: adding service sendline : <unicon.plugins.generic.service_implementation.Sendline object at 0x7fd8e9b08e20>
2023-02-17 14:03:53,555: %UNICON-DEBUG: adding service transmit : <unicon.plugins.generic.service_implementation.Send object at 0x7fd8e9b08df0>
2023-02-17 14:03:53,555: %UNICON-DEBUG: adding service receive : <unicon.plugins.generic.service_implementation.ReceiveService object at 0x7fd8e9b08e80>
2023-02-17 14:03:53,555: %UNICON-DEBUG: adding service receive_buffer : <unicon.plugins.generic.service_implementation.ReceiveBufferService object at 0x7fd8e9b08e50>
2023-02-17 14:03:53,555: %UNICON-DEBUG: adding service expect : <unicon.plugins.generic.service_implementation.Expect object at 0x7fd8e9b08d60>
2023-02-17 14:03:53,556: %UNICON-DEBUG: adding service log_user : <unicon.plugins.generic.service_implementation.LogUser object at 0x7fd8e9b08eb0>
2023-02-17 14:03:53,556: %UNICON-DEBUG: adding service execute : <unicon.plugins.linux.service_implementation.Execute object at 0x7fd8e9b08ee0>
2023-02-17 14:03:53,556: %UNICON-DEBUG: adding service ping : <unicon.plugins.linux.service_implementation.Ping object at 0x7fd8e9b08f10>
2023-02-17 14:03:53,556: %UNICON-DEBUG: adding service expect_log : <unicon.plugins.generic.service_implementation.ExpectLogging object at 0x7fd8e9b08f70>
2023-02-17 14:03:53,556: %UNICON-DEBUG: adding service sudo : <unicon.plugins.linux.service_implementation.Sudo object at 0x7fd8e9b08f40>
2023-02-17 14:03:53,556: %UNICON-DEBUG: adding service trex_console : <unicon.plugins.linux.service_implementation.TrexConsole object at 0x7fd8e9b192e0>
2023-02-17 14:03:53,557: %UNICON-DEBUG: spawn session 'ssh -l -q -o LogLevel=error ' is being launched.
2023-02-17 14:03:53,559: %UNICON-DEBUG: Subprocess 231116 launched as 'ssh -l -q -o LogLevel=error '
2023-02-17 14:03:53,560: %UNICON-INFO: +++ connection to spawn: ssh -l -q -o LogLevel=error , id: 140569610393296 +++
2023-02-17 14:03:53,560: %UNICON-INFO: connection to
Password:
2023-02-17 14:03:54,168: %UNICON-DEBUG: <<< Unicon Got :: '\rPassword: '
2023-02-17 14:03:54,168: %UNICON-DEBUG: *** Pattern List ::
2023-02-17 14:03:54,168: %UNICON-DEBUG: '.+$'
2023-02-17 14:03:54,168: %UNICON-DEBUG:
2023-02-17 14:03:54,168: %UNICON-DEBUG: *** Pattern Matched :: '.+$'
2023-02-17 14:03:54,168: %UNICON-DEBUG: <unicon.eal.MatchMode mode_id=0, mode_name='search multi-line re.S'>
2023-02-17 14:03:54,169: %UNICON-DEBUG:
2023-02-17 14:03:54,192: %UNICON-DEBUG: Statement matched: '[pattern='^.*[Pp]assword( for )?(\S+)?: ?$', action=password_handler, args=None, loop_continue=True, continue_timer=False, trim_buffer=True]'
2023-02-17 14:03:54,192: %UNICON-DEBUG: >>> Unicon Sending :: '\r'
Number of session: 3/6
@ #
2023-02-17 14:03:54,935: %UNICON-DEBUG: <<< Unicon Got :: '\r\nNumber of session: 3/6\r\n\r\n@ # '
2023-02-17 14:03:54,935: %UNICON-DEBUG: *** Pattern List ::
2023-02-17 14:03:54,935: %UNICON-DEBUG: 'Escape character is .*\n'
2023-02-17 14:03:54,935: %UNICON-DEBUG: '^.*RETURN to get started'
2023-02-17 14:03:54,936: %UNICON-DEBUG: 'Are you sure you want to continue connecting \(yes/no(/\[fingerprint\])?\)'
2023-02-17 14:03:54,936: %UNICON-DEBUG: '^.*(Connection refused|Connection reset by peer|Broken pipe|Network is down|closed by remote host)'
2023-02-17 14:03:54,936: %UNICON-DEBUG: 'Received disconnect from .*:'
2023-02-17 14:03:54,936: %UNICON-DEBUG: 'Hit Enter to proceed:'
2023-02-17 14:03:54,936: %UNICON-DEBUG: '^(.*?)Press Ctrl\+x to Exit the session'
2023-02-17 14:03:54,936: %UNICON-DEBUG: '^(.*?)Connected.'
2023-02-17 14:03:54,936: %UNICON-DEBUG: '^.?(%\w+(-\S+)?-\d+-\w+|Guestshell destroyed successfully|%Error opening tftp:\/\/255\.255\.255\.255).$'
2023-02-17 14:03:54,936: %UNICON-DEBUG: '^.?Press any key to continue\..?$'
2023-02-17 14:03:54,936: %UNICON-DEBUG: '^.*[Pp]ermission denied'
2023-02-17 14:03:54,936: %UNICON-DEBUG: '^.*Login incorrect'
2023-02-17 14:03:54,936: %UNICON-DEBUG: '^.*([Uu]sername|[Ll]ogin): ?$'
2023-02-17 14:03:54,937: %UNICON-DEBUG: '^.*[Pp]assword( for )?(\S+)?: ?$'
2023-02-17 14:03:54,937: %UNICON-DEBUG: '^.Enter passphrase for key .?:\s*?'
2023-02-17 14:03:54,937: %UNICON-DEBUG: '^.?(?P[-\w]+)\s?([-\w\]/:\.\d ]+)?([>\$%#\]])\s(\x1b\S+)?$'
2023-02-17 14:03:54,937: %UNICON-DEBUG: '^(.?)(?Ptrex>\s)$'
2023-02-17 14:03:54,937: %UNICON-DEBUG: '^(.*?([>\$%\]]|\] # |[^#\\s]#| #|/|^admin:|^#|\s?#\s?)\s?(\x1b\S+)?)$'
2023-02-17 14:03:54,937: %UNICON-DEBUG:
2023-02-17 14:03:54,937: %UNICON-DEBUG: *** Pattern Matched :: '^.?(?P[-\w]+)\s?([-\w\]/:\.\d ]+)?([>\$%#\]])\s(\x1b\S+)?$'
2023-02-17 14:03:54,937: %UNICON-DEBUG: <unicon.eal.MatchMode mode_id=1, mode_name='search only last line'>
2023-02-17 14:03:54,938: %UNICON-DEBUG: *** Match Groups:: ('', None, '#', None)
2023-02-17 14:03:54,938: %UNICON-DEBUG: Statement matched: '[pattern='^.?(?P[-\w]+)\s?([-\w]/:.\d ]+)?([>$%#]])\s(\x1b\S+)?$', action=update_cur_state, args={'transition': <unicon.statemachine.statetransition.AnyStateTransition object at 0x7fd8e9b08ca0>, 'state': learn_hostname}, loop_continue=False, continue_timer=False, trim_buffer=True]'
2023-02-17 14:03:54,939: %UNICON-DEBUG: Learned hostname(s) : ''.
2023-02-17 14:03:54,940: %UNICON-INFO: Learned hostname:
2023-02-17 14:03:54,940: %UNICON-DEBUG: >>> Unicon Sending :: '\r'
@ #
2023-02-17 14:05:05,967: %UNICON-DEBUG: spawn session 'ssh -l -q -o LogLevel=error ' has been closed.
Traceback (most recent call last):
File "src/unicon/statemachine/statemachine.py", line 737, in unicon.statemachine.statemachine.StateMachine.go_to
File "src/unicon/statemachine/statetransition.py", line 216, in unicon.statemachine.statetransition.StateTransition.do_transitions
File "src/unicon/eal/dialogs.py", line 476, in unicon.eal.dialogs.Dialog.process
File "src/unicon/eal/dialog_processor.py", line 326, in unicon.eal.dialog_processor.SimpleDialogProcessor.process
File "src/unicon/eal/dialog_processor.py", line 285, in unicon.eal.dialog_processor.SimpleDialogProcessor.timeout_handler
unicon.core.errors.TimeoutError: timeout occurred:
timeout value: 60
last_command: '\r'
pattern: ['Escape character is .\n', '^.RETURN to get started', 'Are you sure you want to continue connecting \(yes/no(/\[fingerprint\])?\)', '^.(Connection refused|Connection reset by peer|Broken pipe|Network is down|closed by remote host)', 'Received disconnect from .:', 'Hit Enter to proceed:', '^(.?)Press Ctrl\+x to Exit the session', '^(.?)Connected.', '^.?(%\w+(-\S+)?-\d+-\w+|Guestshell destroyed successfully|%Error opening tftp:\/\/255\.255\.255\.255).$', '^.?Press any key to continue\..?$', '^.[Pp]ermission denied', '^.Login incorrect', '^.([Uu]sername|[Ll]ogin): ?$', '^.[Pp]assword( for )?(\S+)?: ?$', '^.Enter passphrase for key .?:\s*?', '^(.*?([>\$%\]]|\] # |[^#\\s]#| #|/|^admin:|^#|\s?#\s?)\s?(\x1b\S+)?)$']
buffer:'\r\n@ # '
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "src/unicon/bases/connection.py", line 784, in unicon.bases.connection.Connection.connect
File "src/unicon/bases/linux/connection_provider.py", line 62, in unicon.bases.linux.connection_provider.BaseLinuxConnectionProvider.connect
File "src/unicon/bases/linux/connection_provider.py", line 117, in unicon.bases.linux.connection_provider.BaseLinuxConnectionProvider.establish_connection
File "src/unicon/statemachine/statemachine.py", line 740, in unicon.statemachine.statemachine.StateMachine.go_to
unicon.core.errors.StateMachineError: Failed while bringing device to "shell" state
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "connectNet.py", line 21, in
server.connect()
File "src/unicon/bases/connection.py", line 791, in unicon.bases.connection.Connection.connect
unicon.core.errors.ConnectionError: failed to connect to
Failed while bringing device to "shell" state