I have a requirement to get the files in batch mode from an external server and will provide start timestamp as input and end timestamp is current timestamp
**The Find command is giving 6 records as output(in actual server while running manually) but only 5 files are being captured via this script. Any help/guidance would be appreciated.**
以下代码用于连接到源服务器并从同一服务器获取文件
#this is used to connect to the source server
def srcconnect():
try:
conn_handle = paramiko.SSHClient()
conn_handle.load_system_host_keys()
conn_handle.set_missing_host_key_policy(paramiko.AutoAddPolicy())
conn_handle.connect(XXXXX, 22, XXXXX, XXXXXXX)
logging.info("connection handle open for the server")
return conn_handle
except AuthenticationException as error:
logging.info("Conection issue")
raise error
except:
raise
def get_last_file_upload_ts():
try:
#Opening the File to fetch the last run timestamp
filepath = "path/my_file.txt"
with open(filepath) as f:
lastreadts = f.read().replace('\n', '')
logging.info('The start timestamp from where the Files will read : '+lastreadts)
return lastreadts
except:
raise
def execute_command(conn,lastreadts,strt_ts):
try:
command = "find mypath -type f -newermt "+"\""+lastreadts+"\""+' ! -newermt '+"\""+str(strt_ts)+"\""
logging.info(str(command))
stdin, stdout, stderr = conn.exec_command(str(command)+" -ls")
out = stdout.read().decode().strip()
error = stderr.read().decode().strip()
logging.info(stdout.read())
logging.info(out)
logging.info(error)
list_output_files = stdout.read().decode().split('\n')
logging.info(list_output_files)
for i in range(0, len(list_output_files)):
if(len(list_output_files[i])>0):
logging.info('List Data Files'+list_output_files[i])
conn.close()
except:
raise
if __name__ == '__main__':
logging.basicConfig(filename = 'file.log',level = logging.DEBUG,format = '%(asctime)s:%(levelname)s:%(name)s:%(message)s')
strt_ts = datetime.datetime.now()
srchandle = srcconnect()
lastupdts = get_last_file_upload_ts()
execute_command(srchandle,lastupdts,strt_ts)
我做了一些研究,但找不到任何解决方案。是超时问题吗?
预期输出: ls 返回 6 个条目(在服务器中)但脚本只捕获 5 个条目