Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 python3 emulate tail -f on remote server... support required
#1
Hi All,

My source OS is Linux and destination OS Sunos. I am logging to remote server and tailing log file.

my issue

1) I am not able to read tail data line by line
2) Lines are not being split as per actual lines.
3) If I am opening file on remote server with vi editor, shows line by line data.



import paramiko
import select
import time
import re
host = '172.23.96.xx'
port = 22
user = 'nms'
password = 'Nms_123'

client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host, port=port, username=user, password=password)
transport = client.get_transport()
channel = transport.open_session()
channel.exec_command("tail -f /opt/NMS/server/logs/NMSAlarms.log | egrep -v '(VC12|TU12|AU4|VC4|@@SubnetworkConnection)'")

while True:
  stdin,stdout,stderr = select.select([channel],[],[],0.0)
  if len(stdin) > 0:
      line = channel.recv(1024)
      # check new alarm and clear alarm in line
      if 'New Alarm' or 'Clear to Alarm'in line:
          #split line with new line
          print(re.split('\n',line))
          #print # to check line break
          print('#'*20)
      else:
         #no new / clear alarm in line... continue
         continue
  else:
     time.sleep(0.1)
Output:
#################### ['CurrentAlarmsManager.so:__1cKPrintStack4CcnDstdLchar_traits4Cc___6Frn0ANbasic_ostream3CTACTB___4_+0x47', '/opt/NMS/server/lib/libOMFrameWork.so:__1cIDNParserKgetClassDN6FrknJRWCString_3_1_+0x1e83', '/opt/NMS/server/lib/libOMFrameWork.so:__1cIDNParserIgetEmsDN6FrknJRWCString__1_+0x2c', '/opt/NMS/server/patch.lib/NMSAlarms/libCurrentAlarmsManager.so:__1cOAlarmedNMSInfoUgetAlarmedObjectInfo6MrknJRWCString_bb_nSRWTCountingPointer4nRAlarmedObjectInfo_nKRWTCounter4nLRWMutexLock______+0x5e9', '/opt/NMS/server/patch.lib/NMSAlarms/libCurrentAlarmsManager.so:__1cHArchivePgetObjectAlarms6MnJRWCString_pnDstdElist4nSRWTCountingPointer4nMAMSApplEvent_nKRWTCounter4nLRWMutexLock_____n0CJallocator4n0G_____brknFNmsID__v_+0x27b', '/opt/NMS/server/patch.lib/NMSAlarms/libCurrentAlarmsManager.so:__1cUCurrentAlarmsManagerPgetTrailsAlarms6MrknLRWTValSlist4nFNmsID_nDstdJallocator4n0B_____rkn0B_b_pn0CElist4nSRWTCountingPointer4nMAMSApplEvent_nKRWTCounter4nLRWMutexLock_____n0CJallocator4n0I______+0x9af', '/opt/NMS/server/patch.lib/NMSAlarms/libCurrentAlarmsManager.so:__1cUCurrentAlarmsManagerPgetTrailsAlarms6MrknLRWTValSlist4nFNmsID_nDstdJallocator4n0B_____rkn0B__pn0CElist4nSRWTCountingPointer4nMAMSApplEvent_nKRWTCounter4nLRWMutexLock_____n0CJallocator4n0I______+0x6f2', '/opt/NMS/server/bin/NMSAlarms:__1cPCurrentAlarmMgrPgetTrailsAlarms6MXrknFNmsID_rknLRWTValSlist4n0B_nDstdJallocator4n0B______v_+0x571', '/opt/NMS/server/bin/NMSAlarms:__1cQCurrentAlarmImplPgetTrailsAlarms6MrknQGlobalCORBATypesFNmsID_rkn0BKtNmsIDList_nXIT_Cxx_VarLenConstr_out4nIAMSTypesNtAMSEventList____v_+0x7ed', '/opt/NMS/server/bin/NMSAlarms:__1cTPOA_FaultManagementMCurrentAlarmbEgetTrailsAlarms_itgen_dispatch6FpnOPortableServerLServantBase_pnFCORBAQIT_ServerRequest_rn0ERcompletion_status__v_+0x1c41', '/opt/iona/ECILorbix6/shlib/amd64/libit_poa_sc57.so.5:__1cOPortableServerLServantBaseJ_dispatch6MpnFCORBAQIT_ServerRequest__v_+0x124', '/opt/iona/ECILorbix6/shlib/amd64/libit_poa_sc57.so.5:__1cZIT_POA_RequestInterceptorGinvoke6MpnKIT_BindingRServerRequestData_pn0BVServerRequestCallback__v_+0x2bd', '/opt/iona/ECILorbix6/shlib/amd64/libit_iiop_tls_sc57.so.5:__1cLIT_IIOP_TLSbCIT_Checker_ServerInterceptorGinvoke6MpnKIT_BindingRServerRequestData_pn0CVServerRequestCallback__v_+0x3e5', '/opt/iona/ECILorbix6/shlib/amd64/libit_art_sc57.so.5:__1cbCIT_Binding_ServerBindingImplQdispatch_request6MpnKIT_BindingNServerRequest__v_+0x153', '/opt/iona/ECILorbix6/shlib/amd64/libit_giop_sc57.so.5:__1cVIT_GIOP_ServerRequestHexecute6M_nMIT_WorkQdDueueOWorkItemStatus__+0x13d', '/opt/iona/ECILorbix6/shlib/amd64/libit_atli2_ip_sc57.so.5:__1cLIT_ATLI2_IPKIPPoolImplHexecute6M_nMIT_WorkQdDueueOWorkItemStatus__+0x3a9', '/opt/iona/ECILorbix6/shlib/amd64/libit_art_sc57.so.5:__1cUIT_Work_WorkerThreadDrun6M_pv_+0x145', '/opt/iona/ECILorbix6/shlib/posix/amd64/libit_ifc_sc57.so.5:IT_ThreadFactory_call_thread_body+0x10', '/lib/amd64/libc.so.1:0xddbab', '/lib/amd64/libc.so.1:0xddde0', '', 'ERROR [1833:3515441 01/07/20 11:41:41 DNParser.cc:698] > [Throwing exception: ClassNameNotFoundException (1,-32768)] ', ' [1833:3515441 01/07/20 11:41:41 DNParser.cc:697] > ClassNameNotFoundException stacktrace ', '/opt/NMS/server/patch.lib/NMSAlarms/libCurrentAlarmsManager.so:__1cKPrintStack4CcnDstdLchar_traits4Cc___6Frn0ANbasic_ostream3CTACTB___4_+0x47', '/opt/NMS/server/lib/libOMFrameWork.so:__1cIDNParserKgetClassDN6FrknJRWCString_3_1_+0x1e83', '/opt/NMS/server/lib/libOMFrameWork.so:__1cIDNParserIgetEmsDN6FrknJRWCString__1_+0x2c', '/opt/NMS/server/patch.lib/NMSAlarms/libCurrentAlarmsManager.so:__1cOAlarmedNMSInfoUgetAlarmedObjectInfo6MrknJRWCString_bb_nSRWTCountingPointer4nRAlarmedObjectInfo_nKRWTCounter4nLRWMutexLock______+0x5e9', '/opt/NMS/server/patch.lib/NMSAlarms/libCurrentAlarmsManager.so:__1cHArchivePgetObjectAlarms6MnJRWCString_pnDstdElist4nSRWTCountingPointer4nMAMSApplEvent_nKRWTCounter4nLRWMutexLock_____n0CJallocator4n0G_____brknFNmsID__v_+0x27b', '/opt/NMS/server/patch.lib/NMSAlarms/libCurrentAlarmsManager.so:__1cUCurrentAlarmsManagerPgetTrailsAlarms6MrknLRWTValSlist4nFNmsID_nDstdJallocator4n0B_____rkn0B_b_pn0CElist4nSRWTCountingPointer4nMAMSApplEvent_nKRWTCounter4nLRWMutexLock_____n0CJallocator4n0I______+0x9af', '/opt/NMS/server/patch.lib/NMSAlarms/libCurrentAlarmsManager.so:__1cUCurrentAlarmsManagerPgetTrailsAlarms6MrknLRWTValSlist4nFNmsID_nDstdJallocator4n0B_____rkn0B__pn0CElist4nSRWTCountingPointer4nMAMSApplEvent_nKRWTCounter4nLRWMutexLock_____n0CJallocator4n0I______+0x6f2', '/opt/NMS/server/bin/NMSAlarms:__1cPCurrentAlarmMgrPgetTrailsAlarms6MXrknFNmsID_rknLRWTValSlist4n0B_nDstdJallocator4n0B______v_+0x571', '/opt/NMS/server/bin/NMSAlarms:__1cQCurrentAlarmImplPgetTrailsAlarms6MrknQGlobalCORBATypesFNmsID_rkn0BKtNmsIDList_nXIT_Cxx_VarLenConstr_out4nIAMSTypesNtAMSEventList____v_+0x7ed', '/opt/NMS/server/bin/NMSAlarms:__1cTPOA_FaultManagementMCurrentAlarmbEgetTrailsAlarms_itgen_dispatch6FpnOPortableServerLServantBase_pnFCORBAQIT_ServerRequest_rn0ERcompletion_status__v_+0x1c41', '/opt/iona/ECILorbix6/shlib/amd64/libit_poa_sc57.so.5:__1cOPortableServerLServantBaseJ_dispatch6MpnFCORBAQIT_ServerReques'] #################### ['t__v_+0x124', '/opt/iona/ECILorbix6/shlib/amd64/libit_poa_sc57.so.5:__1cZIT_POA_RequestInterceptorGinvoke6MpnKIT_BindingRServerRequestData_pn0BVServerRequestCallback__v_+0x2bd', '/opt/iona/ECILorbix6/shlib/amd64/libit_iiop_tls_sc57.so.5:__1cLIT_IIOP_TLSbCIT_Checker_ServerInterceptorGinvoke6MpnKIT_BindingRServerRequestData_pn0CVServerRequestCallback__v_+0x3e5', '/opt/iona/ECILorbix6/shlib/amd64/libit_art_sc57.so.5:__1cbCIT_Binding_ServerBindingImplQdispatch_request6MpnKIT_BindingNServerRequest__v_+0x153', '/opt/iona/ECILorbix6/shlib/amd64/libit_giop_sc57.so.5:__1cVIT_GIOP_ServerRequestHexecute6M_nMIT_WorkQdDueueOWorkItemStatus__+0x13d', '/opt/iona/ECILorbix6/shlib/amd64/libit_atli2_ip_sc57.so.5:__1cLIT_ATLI2_IPKIPPoolImplHexecute6M_nMIT_WorkQdDueueOWorkItemStatus__+0x3a9', '/opt/iona/ECILorbix6/shlib/amd64/libit_art_sc57.so.5:__1cUIT_Work_WorkerThreadDrun6M_pv_+0x145', '/opt/iona/ECILorbix6/shlib/posix/amd64/libit_ifc_sc57.so.5:IT_ThreadFactory_call_thread_body+0x10', '/lib/amd64/libc.so.1:0xddbab', '/lib/amd64/libc.so.1:0xddde0', '', 'ERROR [1833:3515441 01/07/20 11:41:41 DNParser.cc:698] > [Throwing exception: ClassNameNotFoundException (1,-32768)] ', ' [1833:3515441 01/07/20 11:41:41 DNParser.cc:697] > ClassNameNotFoundException stacktrace ', '/opt/NMS/server/patch.lib/NMSAlarms/libCurrentAlarmsManager.so:__1cKPrintStack4CcnDstdLchar_traits4Cc___6Frn0ANbasic_ostream3CTACTB___4_+0x47', '/opt/NMS/server/lib/libOMFrameWork.so:__1cIDNParserKgetClassDN6FrknJRWCString_3_1_+0x1e83', '/opt/NMS/server/lib/libOMFrameWork.so:__1cIDNParserIgetEmsDN6FrknJRWCString__1_+0x2c', '/opt/NMS/server/patch.lib/NMSAlarms/libCurrentAlarmsManager.so:__1cOAlarmedNMSInfoUgetAlarmedObjectInfo6MrknJRWCString_bb_nSRWTCountingPointer4nRAlarmedObjectInfo_nKRWTCounter4nLRWMutexLock______+0x5e9', '/opt/NMS/server/patch.lib/NMSAlarms/libCurrentAlarmsManager.so:__1cHArchivePgetObjectAlarms6MnJRWCString_pnDstdElist4nSRWTCountingPointer4nMAMSApplEvent_nKRWTCounter4nLRWMutexLock_____n0CJallocator4n0G_____brknFNmsID__v_+0x27b', '/opt/NMS/server/patch.lib/NMSAlarms/libCurrentAlarmsManager.so:__1cUCurrentAlarmsManagerPgetTrailsAlarms6MrknLRWTValSlist4nFNmsID_nDstdJallocator4n0B_____rkn0B_b_pn0CElist4nSRWTCountingPointer4nMAMSApplEvent_nKRWTCounter4nLRWMutexLock_____n0CJallocator4n0I______+0x9af', '/opt/NMS/server/patch.lib/NMSAlarms/libCurrentAlarmsManager.so:__1cUCurrentAlarmsManagerPgetTrailsAlarms6MrknLRWTValSlist4nFNmsID_nDstdJallocator4n0B_____rkn0B__pn0CElist4nSRWTCountingPointer4nMAMSApplEvent_nKRWTCounter4nLRWMutexLock_____n0CJallocator4n0I______+0x6f2', '/opt/NMS/server/bin/NMSAlarms:__1cPCurrentAlarmMgrPgetTrailsAlarms6MXrknFNmsID_rknLRWTValSlist4n0B_nDstdJallocator4n0B______v_+0x571', '/opt/NMS/server/bin/NMSAlarms:__1cQCurrentAlarmImplPgetTrailsAlarms6MrknQGlobalCORBATypesFNmsID_rkn0BKtNmsIDList_nXIT_Cxx_VarLenConstr_out4nIAMSTypesNtAMSEventList____v_+0x7ed', '/opt/NMS/server/bin/NMSAlarms:__1cTPOA_FaultManagementMCurrentAlarmbEgetTrailsAlarms_itgen_dispatch6FpnOPortableServerLServantBase_pnFCORBAQIT_ServerRequest_rn0ERcompletion_status__v_+0x1c41', '/opt/iona/ECILorbix6/shlib/amd64/libit_poa_sc57.so.5:__1cOPortableServerLServantBaseJ_dispatch6MpnFCORBAQIT_ServerRequest__v_+0x124', '/opt/iona/ECILorbix6/shlib/amd64/libit_poa_s'] ####################
remove vi editor shows data line by line

Output:
1 [1833:22 01/07/20 12:04:56 InternalExternalAlarmList.cc:55] > Clear to Alarm was reported on : EMS~~LSN/EMS_XDM_91@@ManagedElement~~2406@@EquipmentHol der~~/rack=1/shelf=1/slot=8/sub_slot=5@@Equipment~~1 CAM ID: 3757896(I7-OTR1 5 ), P.cause 11, native P.C: Low Tx Power , rate : 1 and Qualifier : 513@@65535@@2 EMS ti me: 20200701115956.0 2 [1833:22 01/07/20 12:04:56 CAMAmsSupport.cc:60] > Sending Alarm due : eALARM_DUE_TO_NORMAL_BEHAVIOR CAM ID: 3757896 notifId: 3806019 3 [1833:22 01/07/20 12:04:57 CAMArchive.cc:202] > Alarm notif: EMS~~LSN/EMS_BG-40_200@@ManagedElement~~2338@@PTP~~/shelf=1/slot=9/ebtype=MPS_6F/port=5 ( L12:MPS_6F EoS Port 5-EoS) notifId: 27280109 severity: 5, P.cause 15, rate : 98 Qualifier : 2338@@8@@-1@@-1@@-1@@-1@@-1@@-1@@-1@@16@@4@@6@@4@@335 EMS time: 202007011 15735.0 4 [1833:22 01/07/20 12:04:57 InternalExternalAlarmList.cc:55] > Clear to Alarm was reported on : EMS~~LSN/EMS_BG-40_200@@ManagedElement~~2338@@PTP~~/she lf=1/slot=9/ebtype=MPS_6F/port=5 CAM ID: 3757795(L12:MPS_6F EoS Port 5-EoS), P.cause 15, native P.C: LOFD, rate : 98 and Qualifier : 2338@@8@@-1@@-1@@-1@@-1@@-1@@-1@@- 1@@16@@4@@6@@4@@335 EMS time: 20200701115735.0 5 [1833:22 01/07/20 12:04:57 CAMAmsSupport.cc:60] > Sending Alarm due : eALARM_DUE_TO_NORMAL_BEHAVIOR CAM ID: 3757795 notifId: 27280109 6 [1833:22 01/07/20 12:04:57 CAMArchive.cc:202] > Alarm notif: EMS~~LSN/EMS_BG-40_200@@ManagedElement~~1543@@PTP~~/shelf=1/slot=9/ebtype=MPS_6F/port=4 ( L12:MPS_6F EoS Port 4-VCG) notifId: 27280110 severity: 5, P.cause 0, rate : 99 Qualifier : 1543@@8@@-1@@-1@@-1@@-1@@-1@@-1@@-1@@15@@3@@6@@3@@613 EMS time: 2020070111 5737.0 7 [1833:22 01/07/20 12:04:57 InternalExternalAlarmList.cc:55] > Clear to Alarm was reported on : EMS~~LSN/EMS_BG-40_200@@ManagedElement~~1543@@PTP~~/she lf=1/slot=9/ebtype=MPS_6F/port=4 CAM ID: 3757720(L12:MPS_6F EoS Port 4-VCG), P.cause 0, native P.C: TLCr, rate : 99 and Qualifier : 1543@@8@@-1@@-1@@-1@@-1@@-1@@-1@@-1 @@15@@3@@6@@3@@613 EMS time: 20200701115737.0 8 [1833:22 01/07/20 12:04:57 CAMAmsSupport.cc:60] > Sending Alarm due : eALARM_DUE_TO_NORMAL_BEHAVIOR CAM ID: 3757720 notifId: 27280110 9 [1833:22 01/07/20 12:04:57 CAMArchive.cc:202] > Alarm notif: EMS~~LSN/EMS_BG-40_200@@ManagedElement~~1543@@PTP~~/shelf=1/slot=9/ebtype=MPS_6F/port=5 ( L12:MPS_6F EoS Port 5-VCG) notifId: 27280111 severity: 1, P.cause 0, rate : 99 Qualifier : 1543@@8@@-1@@-1@@-1@@-1@@-1@@-1@@-1@@15@@4@@6@@4@@613 EMS time: 2020070111 5737.0 10 ERROR [1833:22 01/07/20 12:04:57 NmsDataSupport.cc:577] > Object data of type NMS_OBJ_EXTERNAL_ALARM(403) Attribute 6: Wrong index (35) received! Vector len gth 35 11 [1833:22 01/07/20 12:04:57 InternalExternalAlarmList.cc:287] > New Alarm was reported on : EMS~~LSN/EMS_BG-40_200@@ManagedElement~~1543@@PTP~~/shelf=1 /slot=9/ebtype=MPS_6F/port=5 ( L12:MPS_6F EoS Port 5-VCG) with CAM Id : 3758067, P.cause 0, Native P.C: TLCr, rate : 99 and Qualifier : 1543@@8@@-1@@-1@@-1@@-1@@-1@@-1 @@-1@@15@@4@@6@@4@@613 EMS time: 20200701115737.0 12 [1833:22 01/07/20 12:04:57 CAMAmsSupport.cc:60] > Sending Alarm due : eALARM_DUE_TO_NORMAL_BEHAVIOR CAM ID: 3758067 notifId: 27280111 13 [1833:22 01/07/20 12:04:57 CAMArchive.cc:202] > Alarm notif: EMS~~LSN/EMS_BG-40_200@@ManagedElement~~1543@@PTP~~/shelf=1/slot=9/ebtype=MPS_6F/port=5@@ CTP~~/vt2_tu12=7 ( L12:MPS_6F EoS Port 5-VCG:VC12#7) notifId: 27280112 severity: 3, P.cause 27, rate : 11 Qualifier : 1543@@8@@-1@@-1@@-1@@-1@@-1@@15@@4@@3@@6@@6@@4@@ 318 EMS time: 20200701115737.0 14 ERROR [1833:22 01/07/20 12:04:57 NmsDataSupport.cc:577] > Object data of type NMS_OBJ_EXTERNAL_ALARM(403) Attribute 6: Wrong index (35) received! Vector len gth 35 15 [1833:22 01/07/20 12:04:57 InternalExternalAlarmList.cc:287] > New Alarm was reported on : EMS~~LSN/EMS_BG-40_200@@ManagedElement~~1543@@PTP~~/shelf=1 /slot=9/ebtype=MPS_6F/port=5@@CTP~~/vt2_tu12=7 ( L12:MPS_6F EoS Port 5-VCG:VC12#7) with CAM Id : 3758068, P.cause 27, Native P.C: LP-RDI, rate : 11 and Qualifier : 154 3@@8@@-1@@-1@@-1@@-1@@-1@@15@@4@@3@@6@@6@@4@@318 EMS time: 20200701115737.0

https://stackoverflow.com/questions/1596963/read-a-file-from-server-with-ssh-using-python

taken help from above URL
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  python3 regular expression.. support to improve anna 0 120 Jul-07-2020, 09:40 AM
Last Post: anna
  Support required to data log in SQL server single table via raspbeery pi rithikvg 8 312 Jun-23-2020, 05:23 PM
Last Post: buran
  Unable to login to remote SQL Server database sipriusPT 1 995 Dec-20-2019, 10:16 AM
Last Post: sipriusPT
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 692 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE
  python3 regex support anna 3 667 Mar-12-2019, 10:40 AM
Last Post: anna
  how hard is it to emulate print() Skaperen 2 851 Sep-10-2018, 07:11 AM
Last Post: Skaperen
  Take one parameter which is an URL to a remote server ciaranacrowley 1 1,303 Oct-15-2017, 07:44 PM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)