用于计算进入目录的文件数的 Shell 脚本

问题描述:

我有以下场景 -

远程服务器(例如,Server1)使用 FTP 将一些文件推送到另一个服务器(例如,Server 2).然后它更新 Server2 上的数据库,然后自动删除推送的文件.文件会在目录中保留几秒钟.

A remote server(say, Server1) pushes some files into another server(say, Server 2), using FTP. It then updates the database at Server2 and then pushed files are deleted automatically. The files remains in the directory for just few seconds.

我必须编写一个 SHELL SCRIPT 来计算进入目录的这些文件的数量(以分钟为单位).

I have to write a SHELL SCRIPT which will count the number of these files coming in the directory (say in minutes).

PS : Server1 和 Server2 在同一网络路径上

PS : Server1 and Server2 are on the same network path

这将统计最后一分钟内修改的文件.

This will count the files modified during the last minute.

find / -mmin 1|wc -l

每分钟运行一次.

使用 ftpfscurlftpfs.

更新:如果您害怕在几秒钟内丢失一些文件,您可以使用文件的时间戳.您必须依次触摸两个文件才能找到比 t0 新且比 t1 旧的文件.

Update: If you fear to loose some files during a seconds fraction you can use the time stamps of files. You have to touch two files in oder to find those files newer than t0 and older than t1.

初始化开始时间:

touch t0

之后,您可以在循环中执行此操作:

After that you can execute this in a loop:

touch t1
find / -newer t0 -a -not -newer t1 | wc -l
mv t1 t0

这可确保您不会丢失任何文件.

This makes sure that you do not loose any files.