使用看门狗,我希望它在某个目录中查找更新的文件,如果有更新的文件,它会获取文件名并运行具有文件名的特定脚本并将输出作为 txt 文件发送到不同的目录。当文本文件出现在新目录中时,以某种方式获取文件名并将其设置为变量以进行分析。
前任:
第一个目录 /path/to/first/dir/2017/04/27/nfcapd.20170427 <- 新文件(注意,不是 txt 文件)
运行脚本以使用上面的文件名获取下面该文件中的数据
nfdump - r nfcapd.20170427 > home/users/rmaestas/nfcapd.20170427.txt
文件名存储在一个变量中以与代码一起使用
updated = 'nfcapd.21070427.txt’
filename = ('home/users/rmaestas/') #<-- insert 'updated in directory'
with open(filename, 'r') as infile:
next(infile) #Skips the first row, first row is not data.
for line in infile:#read every line
if "Summary:" in line:#End of the data, last4 lines are a summary which won't be needed.
break
print(line.split()[4].rsplit(':', 1)[0])
#more code...