使用kfsmd监控文件系统的变化

本文介绍了一个用于监控Linux文件系统变化的工具kfsmd。通过该工具可以轻松监测指定目录及子目录下的文件变动,并将这些变化记录到控制台输出或数据库中。支持多种Linux发行版。

http://www.linux.com/feature/124903

 

Applications can ask the Linux kernel to report changes to selected files and directories. I created the Kernel Filesystem Monitoring Daemon (kfsmd) to make monitoring filesystem changes simple.

There are packages available for both 32- and 64-bit Fedora 7 and 8 and Ubuntu 7.10 Gutsy, as well as 32-bit packages for openSUSE 10.3. You can also download a repo file, which can be used with Fedora 8 and yum. Placing the repo file into /etc/yum.repos.d allows you to install kfsmd and its dependencies with yum install kfsmd on a Fedora 8 machine. You can also compile directly from source if that is your preference.

Command-line clients for kfsmd come in two categories: monitoring and logging. The monitoring client produces output on the console whenever something happens to a filesystem you are watching. You can log to either a Berkeley DB4 file or a PostgreSQL database.

The following session shows a simple directory monitoring session using kfsmd. It creates and populates a temporary directory, then starts kfsmd-cat to watch /tmp/k for any filesystem changes. The main command-line parameter is the watch command, which takes the directory or file to watch as a single argument. While kfsmd-cat was running, I opened a second terminal and created the df5.txt file and then removed it. These actions were reported to the console by kfsmd.


 
$ mkdir /tmp/k $ cd /tmp/k $ date > df1.txt $ date > df2.txt $ kernel-filesystem-monitor-daemon-cat -v watch . setting up watch for:. setting up watches calling run event on wd:1 . filename:df5.txt CLOSE URL:./df5.txt event on wd:1 . filename:df5.txt DELETE_FILE URL:./df5.txt

If you specify a directory to monitor with a full filesystem path, then kfsmd also monitors existing and newly created subdirectories by default. You can use the ignorepfx argument to limit these recursive monitors by explicitly telling kfsmd not to monitor some subdirectories. In the next example, which uses ignorepfx, I created two subdirectories inside /tmp/k: junk1 and subdir1. Both of the directory create and delete events were reported by kfsmd, and because of the ignorepfx argument, kfsmd did not monitor the /tmp/k/junk1 subdirectory itself, so files I created in that directory were not monitored and reported by kfsmd. Note that as ignorepfx is the prefix of a path, using just "junk" means that the subdirectory junk1 is not monitored.


 
$ kernel-filesystem-monitor-daemon-cat -v \ watch /tmp/k ignorepfx /tmp/k/junk event on wd:1 /tmp/k filename:junk1 CREATE URL:/tmp/k/junk1 event on wd:1 /tmp/k filename:subdir1 CREATE URL:/tmp/k/subdir1 should adding monitor for:subdir1 event on wd:2 /tmp/k/subdir1 filename:subfileA.txt CREATE URL:/tmp/k/subdir1/subfileA.txt event on wd:2 /tmp/k/subdir1 filename:subfileA.txt CLOSE URL:/tmp/k/subdir1/subfileA.txt event on wd:2 /tmp/k/subdir1 filename:subfileA.txt DELETE URL:/tmp/k/subdir1/subfileA.txt event on wd:1 /tmp/k filename:subdir1 DELETE URL:/tmp/k/subdir1 event on wd:1 /tmp/k filename:junk1 DELETE URL:/tmp/k/junk1

You can see that filesystem changes reported by kfsmd have a regular style. The primary report has the prefix "EVENT_TYPE URL:" where the event type is what happened to the file and the URL: string is used as a direct prefix to the file path being reported. This structure makes it convenient to use the kfsmd-cat command and pipe the output into a script that will perform some action for you automatically when files change.

The following script uses Perl to print the paths of files that are deleted in any monitored directory. It uses the pwd command on the first line of the command to make the paths reported by kfsmd absolute. The kfsmd-cat command will produce output similar to that shown above, and Perl code massages the output into a particular format, or can execute a command whenever a deletion happens. The script ignores all lines that do not start with DELET. Lines which report file deletion then have the prefix string "anything...URL:" stripped off so only the file path is printed to the console.


 
$ kernel-filesystem-monitor-daemon-cat watch `pwd` \ | perl -ne '{ if( /^DELET/ ) { s/.*URL://g; print; } }' /tmp/k/df5.txt

A second invocation of kfsmd-cat, shown below, sends an email message whenever a file is deleted in the current directory.


 
$ kernel-filesystem-monitor-daemon-cat watch `pwd` \ | kfsmd-sendemail.pl

The Perl script kfsmd-sendemail.pl is shown below. The three lines which you might have to change to use this yourself are listed at the top of the script; the FromAddress and ToAddress should be modified to suit your local environment.


 
#!/usr/bin/perl -n $Mailer = "| /usr/sbin/sendmail -t"; $FromAddress = 'ben@localhost'; $ToAddress = 'ben@localhost'; if( /^DELETE_/ ) { s/.*URL://g; chomp; $url=$_; $now=`date`; open MAIL,"$Mailer"; print MAIL <<THE_EMAIL; From: $FromAddress To: $ToAddress Subject: KFSMD: A file was deleted The file: $url Was deleted at $now THE_EMAIL close MAIL; }
Logging with kfsmd

To log filesystem events into a PostgreSQL database, use the kfsmd-postgresql command. Before using this command you must set up the database with the postgresql-schema.sql script. This can be done using the first command shown below. Note that the the database setup command only needs to be run once. The kfsmd-postgresql daemon will run in the background by default. You can set up watches with it in the same manner as for the kfsmd-cat command, though you must specify the database host and database name.


 
$ cat postgresql-schema.sql | psql -h myPostgreSQLServer $ kernel-filesystem-monitor-daemon-postgresql \ -h myPostgreSQLServer \ -d kernel_filesystem_monitor_daemon_postgresql watch `pwd`

With the command above, filesystem changes are logged to the PostgreSQL database called kernel_filesystem_monitor_daemon_postgresql on the server myPostgreSQLServer. You can query the database using SQL as shown below.


 
$ psql -h myPostgreSQLServer # \c kernel_filesystem_monitor_daemon_postgresql # select * from dirs d, events e where d.pwd = e.pwd order by time; pwd | url | id | mask | pwd | time | name -----+--------+----+------+-----+----------------------------+---------- 1 | /tmp/k | 2 | 512 | 1 | 2008-01-03 13:26:39.913456 | df11.txt 1 | /tmp/k | 1 | 8 | 1 | 2008-01-03 13:26:39.913456 | df11.txt 1 | /tmp/k | 3 | 8 | 1 | 2008-01-03 13:26:41.917512 | df21.txt

There are many situations where kfsmd is the right tool for the job. For example, if you are editing a file and wish to automatically publish it to a remote server each time it is saved, you can use kfsmd-cat and when a CLOSED event is detected execute a little script to rsync the file to the server. If you have a long-running task and wish to know when it is completed, just monitor for a filesystem change that occurs at the end of the process, such as when a file download or a build completes.

The kfsmd-postgresql and kfsmd-stldb4 commands allow you to easily record filesystem changes in a database, which is great for auditing what happened and when.

【无人车路径跟踪】基于神经网络的数据驱动迭代学习控制(ILC)算法,用于具有未知模型和重复任务的非线性单输入单输出(SISO)离散时间系统的无人车的路径跟踪(Matlab代码实现)内容概要:本文介绍了一种基于神经网络的数据驱动迭代学习控制(ILC)算法,用于解决具有未知模型和重复任务的非线性单输入单输出(SISO)离散时间系统的无人车路径跟踪问题,并提供了完整的Matlab代码实现。该方法无需精确系统模型,通过数据驱动方式结合神经网络逼近系统动态,利用迭代学习机制不断提升控制性能,从而实现高精度的路径跟踪控制。文档还列举了大量相关科研方向和技术应用案例,涵盖智能优化算法、机器学习、路径规划、电力系统等多个领域,展示了该技术在科研仿真中的广泛应用前景。; 适合人群:具备一定自动控制理论基础和Matlab编程能力的研究生、科研人员及从事无人车控制、智能算法开发的工程技术人员。; 使用场景及目标:①应用于无人车在重复任务下的高精度路径跟踪控制;②为缺乏精确数学模型的非线性系统提供有效的控制策略设计思路;③作为科研复现与算法验证的学习资源,推动数据驱动控制方法的研究与应用。; 阅读建议:建议读者结合Matlab代码深入理解算法实现细节,重点关注神经网络与ILC的结合机制,并尝试在不同仿真环境中进行参数调优与性能对比,以掌握数据驱动控制的核心思想与工程应用技巧。
本项目提供了一套完整的基于Python编程语言的医学影像分析解决方案,专门针对三维计算机断层扫描图像中的肺部结节识别任务。该资源包包含了经过优化的检测算法源代码、经过标注的医疗影像数据集以及详细的技术文档说明。 本方案源自一项优秀的学术研究课题,在毕业答辩环节获得了接近满分的评价。所有程序模块均通过多轮功能验证与稳定性测试,具备良好的可执行性。这套工具适合计算机科学、电子信息工程、智能系统与控制等相关领域的师生及科研人员参考使用,既可作为教学实践的辅助材料,也可用于课程项目、学术竞赛或学位论文等科研活动。 该资源具有显著的教学价值与科研参考意义,其中采用的深度学习框架包含了数据预处理、特征提取和分类识别等完整流程。对于具备扎实编程基础的用户,可以根据实际需求对网络结构、参数设置和后处理流程进行个性化调整,以拓展其在不同医疗影像分析场景中的应用范围。 技术实现方面,系统采用卷积神经网络架构处理三维体数据,通过多尺度特征融合机制提升小尺寸结节的检测灵敏度。数据集包含经过专业放射科医师标注的肺部CT序列,涵盖了不同尺寸、形态和密度的典型结节病例。项目文档详细阐述了算法原理、环境配置指南和性能评估指标,为初学者提供系统的学习路径,同时为研究人员提供可靠的实验基准。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
包含了丰富的EWB (Electronic Workbench) 和 Multisim 电子电路仿真实例,专为电子爱好者、学生以及工程师设计。这些实例集合了多年来的精心搜集与整理,覆盖广泛的知识点,适合用于教学、学习和项目开发。总大小超过50MB的资源,提供了详尽的电路设计案例,帮助用户深入理解电路原理与仿真操作。 文件结构 资源以目录树的形式组织,确保用户能够轻松找到各类电路仿真文件: 仿真实验:包含555定时器电路、基本放大电路、滤波器、数字电路实验等,适用于各种模拟与数字电路的学习。 其他:涵盖独立的电路测试,如L/C谐振、RLC滤波器、电源调节等。 数字电子仿真实验:系统地排列了从基本逻辑门到复杂的时序逻辑电路的仿真。 模拟电子仿真实验:专注于二极管、三极管、MOSFET的应用,包括放大器、滤波器、稳压电路等。 此外,还特别针对特定主题(如SD01至SD09)进行了分类,每个部分都详细讲解了一组相关的电路,从简单的二极管电路到复杂的数字系统设计都有涉及。 使用指南 这些文件主要以.ms10、.ms9和.ewb格式存在,需要在EWB或者Multisim软件环境下打开和运行。通过这些实例,用户可以直观地观察电路的工作状态,进行参数调整以加深对电路行为的理解。 注意事项 确保你的计算机上安装有兼容这些文件格式的最新版本的EWB或Multisim软件。 在使用前,请仔细阅读各个文件夹内的说明文档,以充分利用每一个示例的价值。 对于初学者,建议从基础电路开始,逐步过渡到更复杂的系统。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值