简体   繁体   English

linux系统中的某个目录是否创建日志文件,如何保持查看? 使用 python

[英]How to keep checking a directory in linux system if a log file is created or no? Using python

A feature will be launched which will create logs as the run proceeds.将启动一项功能,该功能将在运行过程中创建日志。 So, I have to write a script which will keep on checking a directory during runtime of the about feature if there are any log files created or no and incase if I see the logs being created, I will do further actions.因此,我必须编写一个脚本,该脚本将在关于功能的运行时继续检查目录是否创建了任何日志文件,如果我看到正在创建的日志,我将执行进一步的操作。 The tricky part here is I do not have access to watch, cron jobs or anything like that at customer site so any other suggestion would be appreciated.这里棘手的部分是我无法在客户站点访问 watch、cron 作业或类似的东西,因此任何其他建议将不胜感激。 Also, I cannot install any python libraries, so I need something very basic.另外,我无法安装任何 python 库,所以我需要一些非常基本的东西。

I haven't yet tried but looking to see if any function exists, I am planning to use while loop to keep monitoring the directory.我还没有尝试过,但想看看是否存在任何 function,我打算使用 while 循环来继续监视目录。

If you cannot convince the client to install inotify-tools in order to have access to inotifywait , then you need to keep track of not only the existence of an output file, but, more important, is the output file closed (is the process finished with that file).如果您无法说服客户端安装inotify-tools以访问inotifywait ,那么您不仅需要跟踪 output 文件的存在,而且更重要的是,output 文件是否已关闭(进程是否已完成与该文件)。

In other words the process creating the file would have a second " flag file " (call it ${process_name}.writing ) which would be created before output and removed when output completed.换句话说,创建文件的进程将有第二个“标志文件”(称为${process_name}.writing ),它将在 output 之前创建并在 output 完成时删除。

As for conditional logic, if output.txt exists and ${process_name}.writing does not, then the output.txt is complete and usable .至于条件逻辑,如果output.txt存在而${process_name}.writing不存在,那么output.txt是完整可用的。

You can always consider use of the flock utility to test/assign reserved use of file in order to ensure no conflicts in acquisition of "closed" files.您始终可以考虑使用flock实用程序来测试/分配文件的保留使用,以确保在获取“已关闭”文件时不会发生冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在 Linux 中使用 python 提取 zip 文件时的目录相关问题,其中 zip 在窗口系统中使用 java 8 创建 - Directory related issue while I am extracting zip file using python inside Linux where zip created in window system using java 8 使用Python检查Linux目录权限 - Checking Linux Directory Permissions with Python 使用Python过滤Linux日志文件 - filter a Linux log file using Python 使用 Linux 或 Python 按目录拆分 zip 文件 - Split zip file by directory using Linux or Python Python - 检查今天是否创建了文件 - Python - Checking if file is created today 使用 Python 检查 Linux 中的文件权限 - Checking File Permissions in Linux with Python 使用 Python 和 ftplib 检查 FTP 服务器上的对象是文件还是目录 - Checking if object on FTP server is file or directory using Python and ftplib 如何使用Python脚本在文本文件或日志文件中写入时间(本地系统时间)? - How to write time (local system time), in text file or in log file using a Python script? 如何将创建的Zip文件保存到python中的文件系统中? - How to save created Zip file to file system in python? 使用 python 将在临时目录中创建的文件上传到 SharePoint - Upload file created in temporary directory into SharePoint using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM