Linux Perl:如何查找文件是否存在并读取它(如果存在)-> REALTIME

Linux Perl: How to look for the existence of a file and read it, if it exist -> REALTIME

类似的问题也有,但我追求的是实时检测文件是否存在

我有2个linuxbox/PC.

[Linux 框 1] -> 生成一个名为 host 的文件(手动执行)

[Linux 框 2] -> 有一个守护进程每 2 秒休眠一次,检查预期的文件是否存在。如果它存在,它将执行我的 ssh 命令(当然,我们会显示一堆文本,表明它已被执行 bla bla bla)。

PERL 脚本:

ctr:
if (-e $file) { system ("ssh $script $host.$display"); } 
sleep(2);
goto ctr;

问题 问题是,我似乎无法确定文件是否实时存在,即使它已经存在。

BOX 1

[machine01:/home/machine01]% /MACHINE/TOOLS/perl/app/host_gen
> executed at 08/21/2015 21:40:32

框 2

Sleeping for 2 seconds [08/21/2015 21:40:22]
Sleeping for 2 seconds [08/21/2015 21:40:24]
Sleeping for 2 seconds [08/21/2015 21:40:26]
Sleeping for 2 seconds [08/21/2015 21:40:28]
Sleeping for 2 seconds [08/21/2015 21:40:30]
Sleeping for 2 seconds [08/21/2015 21:40:32] **<-expected execution**
Sleeping for 2 seconds [08/21/2015 21:40:34]
Sleeping for 2 seconds [08/21/2015 21:40:36]
Sleeping for 2 seconds [08/21/2015 21:40:38]
Sleeping for 2 seconds [08/21/2015 21:40:40]
Sleeping for 2 seconds [08/21/2015 21:40:42]
Sleeping for 2 seconds [08/21/2015 21:40:44]
Sleeping for 2 seconds [08/21/2015 21:40:46]
Sleeping for 2 seconds [08/21/2015 21:40:48]
Sleeping for 2 seconds [08/21/2015 21:40:50]
Sleeping for 2 seconds [08/21/2015 21:40:52]
Sleeping for 2 seconds [08/21/2015 21:40:54]
Sleeping for 2 seconds [08/21/2015 21:40:56]
Sleeping for 2 seconds [08/21/2015 21:40:58]
Sleeping for 2 seconds [08/21/2015 21:41:00]
Sleeping for 2 seconds [08/21/2015 21:41:02]
Sleeping for 2 seconds [08/21/2015 21:41:04]
Sleeping for 2 seconds [08/21/2015 21:41:06]
Sleeping for 2 seconds [08/21/2015 21:41:08]
Sleeping for 2 seconds [08/21/2015 21:41:10]
Sleeping for 2 seconds [08/21/2015 21:41:12] <- It was executed here
TYPE_AND_DISPLAY [wkss machine01.ult.ultera.omps.com:0]
TYPE [wkss] DISPLAY [machine01.ult.ultera.omps.com:0]

检测现有文件几乎需要一分钟,有时需要 10 秒。

太奇怪了。

你们知道我怎样才能实现我的目标吗?

提前致谢。

Prior serverfault.com question: How can I tell if a file is on a remote filesystem with Perl?

引自该线程;

By default, most NFS clients cache directory information for 60 seconds.

该线程中提到的解决方案:

Mount the NFS share on the client with the noac option to disable attribute caching, or use acdirmin=0,acdirmax=0 to just disable directory caching.