hi there. i got this resolved using paramiko. this is my code.
below is my code to achieve this
Code:
nbytes = 4096
hostname = '10.86.8.129'
port = 22
username = 'root'
password = '123456'
command = 'stat -c%Y /usr/local/testlogs/logfiles/*'
client = paramiko.Transport((hostname, port))
client.connect(username=username, password=password)
stdout_data = []
stderr_data = []
session = client.open_channel(kind='session')
session.exec_command(command)
while True:
if session.recv_ready():
stdout_data.append(session.recv(nbytes))
if session.recv_stderr_ready():
stderr_data.append(session.recv_stderr(nbytes))
if session.exit_status_ready():
break
#print 'exit status: ', session.recv_exit_status()
#print ''.join(stdout_data)
#print ''.join(stderr_data)
results = ''.join(stdout_data)
results2 = ''.join(stderr_data)
result = results.split('\n')
for val in result :
if val != val[:-1] :
age = (time.time() - float(val)) / 60
if age > 1440 :
print "File is older than 1 day"
else :
print "File is still below 1 day old"
thank you very much for you help!