Untitled
unknown
plain_text
2 years ago
1.3 kB
4
Indexable
This is one function- def purge_logs(): vm_details = get_vm_details() for vm in vm_details: vm_id = vm['vm_id'] vm_ip = vm['vm_ip'] syslog_file = vm['syslog_file_location'] retention_period = get_retention_period(vm_id) print("VM:", vm_id) print("VM_IP:", vm_ip) bookmark_record=str(vm_ip) + "_bookmark_log" print("Bookmark record ",bookmark_record) print("Syslog File Location:", syslog_file) print("Retention Period:", retention_period) current_date = str(datetime.datetime.now()).split(' ')[0] print(current_date) #print("Purging Logs...") try: with open(syslog_file,'r') as file: for line in file: if str(current_date) in line: #print(line) x = line except Exception as e: print("File not found :",e) purge_logs() here in try block we need first occurence of that line found and note its line number and all the lines before that line should be deleted/purged . Can you help here please as based on current date we are finding the first line of today's date and deleting all earlier records.
Editor is loading...
Leave a Comment