我正在尝试在中处理Linux输出
以下是我在Linux上的输出:
machine01:/mnt/vlm/log-prod machine02:/mnt/machine01_vlm/log-prod Transferred 17:46:14 Idle
machine01:/mnt/vlm/log-test machine02:/mnt/machine01_vlm/log-test Transferred 17:46:14 Idle
machine01:/mnt/wndchl/- machine02:/mnt/machine01_wndchl/machine01_wndchl_machine01_wndchl Transferred 18:36:10 Idle
machine01:/mnt/wndchl/prod machine02:/mnt/machine01_wndchl/prod Transferred 18:36:10 Idle
machine01:/mnt/wndchl/test machine02:/mnt/machine01_wndchl/test Transferred 18:36:10 Idle
machine01:/mnt/iso/Archive machine02:/mnt/iso/Archive Transferred 19:06:10 Idle
machine01:/mnt/iso/Ready To Transfer machine02:/mnt/iso/ReadyxToxTransfer Transferred 19:06:10 Idle
machine01:/mnt/iso/- machine02:/mnt/iso/iso_machine01_iso Transferred 19:06:10 Idle
machine01:/mnt/it/SCCM machine02:/mnt/it/SCCM Transferred 19:25:51 Idle
machine01:/mnt/it/Windows machine02:/mnt/it/Windows Transferred 19:25:51 Idle
machine01:/mnt/it/- machine02:/mnt/it/machine01_it_machine01_it Transferred 19:25:51 Idle
machine01:/mnt/it/dcs machine02:/mnt/it/dcs Transferred 19:25:51 Idle
machine01:/mnt/it/hds_perf_logs machine02:/mnt/it/hds_perf_logs Transferred 19:25:51 Idle
machine01:/mnt/legalhold/LegalHold machine02:/mnt/legalhold/LegalHold Transferred 18:46:06 Idle
machine01:/mnt/legalhold/- machine02:/mnt/legalhold/legalhold_machine01_legalhold Transferred 18:46:06 Idle
这是我的python脚本
for x in f.readlines():
output_data = x.split()
#Define variable
source_path = output_data[0]
dest_path = output_data[1]
print "working on....",source_path
relationship = output_data[2]
#We are only interested with hour,split it out!
buffer_time = output_data[3].split(":",1)
relationship_status = output_data[4]
#Get destination nas hostname
dest_nas = output_data[1].split(":",1)
dest_nas_hostname = dest_nas[0]
#Get the exact hour number and convert it into int
extracted_hour = int(buffer_time[0])
if relationship_status == "Idle":
if extracted_hour > max_tolerate_hour:
print "Source path : ",source_path
print "Destination path : ",dest_path
print "Max threshold(hours): ",max_tolerate_hour
print "Idle (hours) : ",extracted_hour
print "======================================================================"
else:
pass
print "Scan completed!"
一切似乎都很好,但它打破时,从第7行空间,“准备转移”搞砸了脚本。。。我可以把try&except放进去,但它没有解决问题。你知道吗
请告诉我还能做什么?你知道吗
可以基于正则表达式进行拆分。此正则表达式匹配多个空格:
如果文件名有多个空格,则仍会中断。我建议使用更为定制的正则表达式:
编辑:regex在“machine02:/mnt/machine01\vlm/log prod”上坏了,试试这个
这里有一个到Pythonre module文档的链接
实验正则表达式的一个好工具是https://www.debuggex.com/
针对给定的数据返回运行
相关问题 更多 >
编程相关推荐