有没有更好的方法来运行脚本作为守护进程,它不断轮询目录以检查文件的存在?

时间:2017-04-25 13:17:03

标签: shell unix

我必须不断检查特定目录中是否存在文件。我使用git checkout branchB git merge develop 脚本执行此操作:

filecopy.sh

我希望#!/bin/bash while true; do if [ -f /var/tmp/*.*cim ]; then echo "Checking the file available in the path" mv /var/tmp/*.*cim /etc/opt/maptranslator/ss7 /etc/init.d/ss7-stack restart else continue; fi done 脚本作为守护进程运行。我写了以下脚本:

filecopy.sh

我想知道是否有更好的方法来实现这一目标。

1 个答案:

答案 0 :(得分:0)

编写一个调用inotify(7)的小型C程序。

请参阅http://man7.org/linux/man-pages/man7/inotify.7.htmlman 7 inotify

在这种情况下,您正在等待/var/tmp更改。

但是你真的不应该使用/var/tmp,除非你想让一些随机用户管理你的保护区。针对在/var/tmp中创建其pid文件的进程提交安全错误。

相关问题