Posts: 221
Threads: 71
Joined: Dec 2017
Is there an exception traceback?
No exception traceback
Does the remote command execute successfully? Your program needs to check this.
Remote command is execute successfully.. however its not printing whole output, printing less output
Does the stdout.readlines() read all the lines that you're expecting. If not, why?
stdout.readlines() not reading all the lines, what could be the issue?
Is there anything in the command's stderr stream?
not able to understand this
Posts: 4,780
Threads: 76
Joined: Jan 2018
(Apr-24-2018, 09:38 AM)anna Wrote: not able to understand this try print(("STDERR'S CONTENT:", stderr.read())) in order to see if the command printed anything in the error stream.
Posts: 221
Threads: 71
Joined: Dec 2017
post changing code as per your suggestion, its printing data, but how to regex for desired output.
import re
import atexit
import paramiko
import time
import logging
import time
stat_time = time.time()
class myssh:
def __init__(self, host, user, password, port = 22):
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)
atexit.register(client.close)
self.client = client
def __call__(self, command):
stdin,stdout,stderr = self.client.exec_command(command)
print(("STDERR'S CONTENT:", stderr.read()))
remote = myssh('172.23.96.66','nms','Ttml_nms')
remote('/opt/NMS/server/bin/NMSState')
print('It took', time.time()- stat_time, 'seconds.') Output: ME:<PUN_YOUBB_NPT1200> IP:<192.9.52.204> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~6594> Full Upload:<UPLOADED>\n ME:<PUN_Dongkwang_Precision BG20> IP:<192.9.97.218> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~6903> Full Upload:<UPLOADED>\n ME:<Murud_BG20_2> IP:<192.9.34.61> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~6679> Full Upload:<UPLOADED>\n ME:<KOL_MANIKNAGAR_BG20B> IP:<192.9.83.138> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~6488> Full Upload:<UPLOADED>\n ME:<Harihareshwar> IP:<192.9.34.37> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~6499> Full Upload:<UPLOADED>\n ME:<NSK_Ozar MPLS BG 20> IP:<192.9.62.210> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~6450> Full Upload:<UPLOADED>\n ME:<PUN_INSPIRAGE_SOFTWARE> IP:<192.9.30.10> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~6492> Full Upload:<UPLOADED>\n ME:<PUN_DELFINGEN_INDIA> IP:<192.9.30.218> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~6728> Full Upload:<UPLOADED>\n ME:<GOA_Taj_Exotica_BG20_2nd> IP:<192.9.171.79> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~6516> Full Upload:<UPLOADED>\n ME:<NSK_MehrunNagar_BG20> IP:<192.9.93.107> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~6558> Full Upload:<UPLOADED>\n ME:<PUN_SHIRUR_BG64> IP:<192.9.97.221> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~9136> Full Upload:<UPLOADED>\n ME:<AUR_SUPE_BG64> IP:<192.9.57.75> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~9137> Full Upload:<UPLOADED>\n ME:<PUN_Sunshine_BSC-1_BG20B> IP:<192.9.51.1> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~8816> Full Upload:<UPLOADED>\n ME:<PUN_Tapkir nagar Moshi> IP:<192.9.92.227> Core Upload:<NOT_UPLOADED> Full Upload:<NOT_UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~1297> Full Upload:<NOT_UPLOADED>\n ME:<KOL_Mahud_Rd> IP:<192.9.73.232> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~1009> Full Upload:<UPLOADED>\n ME:<GOA-Anup_01> IP:<192.9.79.209> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~826> Full Upload:<UPLOADED>\n ME:<GOA-Royal_Tower_Ponda> IP:<192.9.47.70> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3290> Full Upload:<UPLOADED>\n ME:<NGP_GONDIA (MUNDIPAR) MIDC> IP:<192.9.95.134> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~956> Full Upload:<UPLOADED>\n ME:<KOL_Pachapeth_BG20> IP:<192.9.171.196> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3103> Full Upload:<UPLOADED>\n ME:<NGP_Bus Stand_INDUS> IP:<192.9.32.67> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~887> Full Upload:<UPLOADED>\n ME:<KOL_BarshiP5_2_BG> IP:<192.9.171.219> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3848> Full Upload:<UPLOADED>\n ME:<GOA_Dona Paula Kings palace> IP:<192.9.47.160> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~94> Full Upload:<UPLOADED>\n ME:<KOL_Shivaji_peth-2> IP:<192.9.75.76> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3068> Full Upload:<UPLOADED>\n ME:<KOL_TimberSangli> IP:<192.9.83.145> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3115> Full Upload:<UPLOADED>\n ME:<KOL_Udgir-Market> IP:<192.9.78.204> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3714> Full Upload:<UPLOADED>\n ME:<NGP_Patwa Chowk_INDUS> IP:<192.9.69.145> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~961> Full Upload:<UPLOADED>\n ME:<AUR_Nirala BazarBG20> IP:<192.9.74.194> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~867> Full Upload:<UPLOADED>\n ME:<GOA-Map Hsg Brd> IP:<192.9.79.207> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~1548> Full Upload:<UPLOADED>\n ME:<KOL_Phulewadi_BG20> IP:<192.9.75.80> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~941> Full Upload:<UPLOADED>\n ME:<NGP_Umred WCL_VIOM> IP:<192.9.39.121> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3873> Full Upload:<UPLOADED>\n ME:<PUN_Shirur_GTL> IP:<192.9.57.135> Core Upload:<NOT_UPLOADED> Full Upload:<NOT_UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3507> Full Upload:<NOT_UPLOADED>\n ME:<NGP_Pallavi Apts_INDUS> IP:<192.9.92.66> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3026> Full Upload:<UPLOADED>\n ME:<PUN_padmaprabha> IP:<192.9.37.202> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3300> Full Upload:<UPLOADED>\n ME:<AUR_Jatwada-Road> IP:<192.9.91.161> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3066> Full Upload:<UPLOADED>\n ME:<KOL_Tung> IP:<192.9.20.93> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3022> Full Upload:<UPLOADED>\n ME:<PNMS MGMT> IP:<192.9.66.3> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~2047> Full Upload:<UPLOADED>\n ME:<AUR_Polytechnic college_Beed> IP:<192.9.67.78> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~1685> Full Upload:<UPLOADED>\n ME:<NSK_TA Gate-UT-Deolali_Camp(15> IP:<192.9.170.213> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3576> Full Upload:<UPLOADED>\n ME:<HotelSapnaBg20C> IP:<192.9.38.26> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~5048> Full Upload:<UPLOADED>\n ME:<NGP_SiddheshwarNagar_INDUS> IP:<192.9.92.80> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~991> Full Upload:<UPLOADED>\n ME:<AUR_N6-Bari-colony> IP:<192.9.26.166> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3674> Full Upload:<UPLOADED>\n ME:<NGP_Railtoli_VIOM> IP:<192.9.95.132> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~990> Full Upload:<UPLOADED>\n ME:<NGP_New Friends Colony( Akar)> IP:<192.9.170.98> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~8801> Full Upload:<UPLOADED>\n ME:<AUR_ Roshangate_Haji Ali> IP:<192.9.26.168> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~1919> Full Upload:<UPLOADED>\n ME:<PUN_Jairaj bldg> IP:<192.9.98.137> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~1247> Full Upload:<UPLOADED>\n ME:<PUN_PanchshilRd_Baramati> IP:<192.9.58.79> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~1556> Full Upload:<UPLOADED>\n ME:<NSK_PanchwatiKaranja-BG-20> IP:<192.9.61.218> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3208> Full Upload:<UPLOADED>\n ME:<NGP_ShaktiNagar_INDUS> IP:<192.9.31.23> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~986> Full Upload:<UPLOADED>\n ME:<NSK_PatelColonyBG-20> IP:<192.9.72.147> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~923> Full Upload:<UPLOADED>\n ME:<NGP_Surendra Nagar_VIOM> IP:<192.9.241.15> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3075> Full Upload:<UPLOADED>\n ME:<PUN_Mayfair_tower-BG> IP:<192.9.51.206> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~1716> Full Upload:<UPLOADED>\n ME:<KOL_Ganesh_Nagar_BG20> IP:<192.9.87.21> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3399> Full Upload:<UPLOADED>\n ME:<Vidhya-nagar> IP:<192.9.55.138> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~601> Full Upload:<UPLOADED>\n ME:<AUR_Ambika Nagar_Beed> IP:<192.9.67.84> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3063> Full Upload:<UPLOADED>\n ME:<PUN_Pashankar_auto2> IP:<192.9.94.3> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3232> Full Upload:<UPLOADED>\n ME:<KOL_Nimshirgaon_BG20> IP:<192.9.20.147> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~1652> Full Upload:<UPLOADED>\n ME:<KOL_UT_Ganjagolai_BG20> IP:<192.9.79.77> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3493> Full Upload:<UPLOADED>\n ME:<NAGAR_MIDC-2> IP:<192.9.57.31> Core Upload:<UPLOADED> Full Upload:<UPLOADED>\n SN:<EMS~~LSN/EMS_BG-40_105@@MultiLayerSubnetwork~~3119> Full Upload:<UPLOADED>\n ME:<Aircel_Sangamner_BG> IP:<192.9.53.71> Core Upload:<NOT_UPLOADED> Full Upload:<NOT_UPLOADED>\n
Posts: 4,780
Threads: 76
Joined: Jan 2018
Apr-24-2018, 10:57 AM
(This post was last modified: Apr-24-2018, 10:58 AM by Gribouillis.)
Is all this output printed to stderr? It is suprising. You could do stderr.readlines() instead of read() and parse the lines as you did before for stdout.
However, you could perhaps run the command NMSState in a ssh session outside of python to understand how it works. Also look in this command's documentation and options.
Posts: 221
Threads: 71
Joined: Dec 2017
changes done for stderr.read(), but printing output one character per line
sshdata = stderr.read()
for line in sshdata:
print line Output: M
E
:
<
P
U
N
_
K
a
m
a
l
a
_
C
o
r
n
e
r
_
X
D
M
3
0
0
>
I
P
:
<
1
9
2
.
9
.
6
1
.
1
7
9
>
C
o
r
e
U
p
l
o
a
d
:
<
U
P
L
O
A
D
E
D
>
F
u
l
l
U
p
l
o
a
d
:
<
U
P
L
O
A
D
E
D
>
Posts: 4,780
Threads: 76
Joined: Jan 2018
Posts: 221
Threads: 71
Joined: Dec 2017
Done, thanks.
import re
import atexit
import paramiko
import time
import logging
import time
stat_time = time.time()
class myssh:
def __init__(self, host, user, password, port = 22):
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)
atexit.register(client.close)
self.client = client
def __call__(self, command):
stdin,stdout,stderr = self.client.exec_command(command)
sshdata = stderr.readlines()
for line in sshdata:
if 'ME:' in line:
pattern = r'(?<=\<).+?(?=\>)'
result = re.findall(pattern, line)
print (','.join(result))
remote = myssh('172.23.96.66','nms','Ttml_nms')
remote('/opt/NMS/server/bin/NMSState')
time.sleep(10)
total_time=time.time()- stat_time
print('It took', time.time()- stat_time, 'seconds.') Output: KOL_Nesari_XDM100,192.9.47.2,UPLOADED,UPLOADED
PUN_ButtePatil,192.9.21.4,UPLOADED,UPLOADED
Waluj_XDM-100,192.9.76.1,UPLOADED,UPLOADED
PUN_Goyal-DWDM_(TTML),192.9.37.131,UPLOADED,UPLOADED
KOL_BHUM_XDM-100,192.9.240.134,UPLOADED,UPLOADED
PUN_JEJURI_5H1_VSNL,192.9.44.37,UPLOADED,UPLOADED
KOL_Umerga_xdm100,192.9.73.211,UPLOADED,UPLOADED
GOA-TRISTAR_BB_XDM100-6,192.9.49.5,UPLOADED,UPLOADED
Pen_Bsc_xdm100_2,192.9.89.120,UPLOADED,UPLOADED
NGP_NAGPURXDM100-4,192.9.43.92,UPLOADED,UPLOADED
Nasik_Switch_XDM100_9,192.9.62.209,UPLOADED,UPLOADED
NGP_Aamgaon_XDM100_VIOM,192.9.95.129,UPLOADED,UPLOADED
PANVEL_BB_1K,192.9.89.107,UPLOADED,UPLOADED
Turbhe-BB1,192.9.89.106,UPLOADED,UPLOADED
PUN_XDM100-4,192.9.71.1,UPLOADED,UPLOADED
fail to understand .. why stderr.readlines() working?
Posts: 4,780
Threads: 76
Joined: Jan 2018
(Apr-24-2018, 11:08 AM)anna Wrote: fail to understand .. why stderr.readlines() working? The answer is in the NMSState command. It is not a python problem.
|