xml - 如何查看文件夹中的新文件,然后将新文件作为 $1 执行脚本

标签 xml linux bash

我有一个 Windows 应用程序将创建一个 .xml 文件并将其上传到我的 Linux 服务器上的一个文件夹中。我需要一种方法来监视这个新文件,它的文件名类似于“004job.xml”、“012job.xml”等。文件名每次都不一样。检测到文件后,将使用新文件作为其命令行变量运行脚本。像这样“/home/project/scripts/renderjob.sh/home/project/jobs/012job.xml”。脚本会根据.xml文件的内容做一些 Action ,最后的 Action 是删除.xml文件。

同样重要的是,一次只运行此脚本的一个实例。但那是一匹不同颜色的马。

感谢阅读。

最佳答案

简要说明:

After the file is detected, a script would be run with the new file as its command line variable.

https://unix.stackexchange.com/questions/273556/when-a-particular-file-arrives-then-execute-a-procedure-using-shell-script/273563#273563

Its also important that only one instance of this script is running at a time.

以这种方式在脚本中使用 flock:https://unix.stackexchange.com/questions/274498/performing-atomic-write-operations-in-a-file-in-bash/274499#274499 .在 flock 中插入监视你的文件:

(
    flock -s 200

    res=$(inotifywait $DIR)
    # other actions

) 200>/var/lock/myscriptlock 

关于xml - 如何查看文件夹中的新文件,然后将新文件作为 $1 执行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37102579/

相关文章:

java - 我需要手动关闭输入流吗?

java - Android FrameLayout 中的 ProgressBar 永远不可见

linux - 在 Emacs 中取消绑定(bind) C-d 和删除

linux - 使用批处理文件或 shell 脚本进行文件传输

linux - 有没有办法检索用户定义命令调用的脚本路径?

用于 RSS 提要解析的 Objective-C 库?

c# - XML XNA 对象反序列化

Visual Studio 上的 C 或 C++

c - 如何从保存的格式字符串和参数中形成一个字符串并在 gdb 中打印

linux - 使用 find 排除目录并压缩目录中的其他所有内容