监视触发器文件并复制该目录中的所有文件
Monitor for trigger file and copy all files in that directory
我是 Unix 脚本的新手。对不起,如果这个问题听起来很愚蠢。
我有一个脚本可以将文件从 Landingzone 复制到存档目录。
现在,我想编写一个脚本来检查 test.txt 文件(类似于触发器文件),只有在找到文件后才复制 test.txt 之前到达的所有文件=17=] 文件从 Landingzone 到 Archive。请让我知道该怎么做?
我将其称为脚本是因为除了复制之外我还有更多命令。
这应该有效
ARCHIVE=... # archive directory
cd Landingzone
if [ -f test.txt ]; then
find . -type f -maxdepth 1 ! -name test.txt ! -newer test.txt -exec cp {} $ARCHIVE ';'
fi
说明:
感谢 if [ -f ... ];仅当 test.txt 存在时才会执行所有操作。然后我们调用 find to
- 仅搜索普通文件 ('-f')
- 排除子目录 (-maxdepth 1)
- 排除 test.txt 本身 (!-name test.txt)
- 排除比 test.txt 更新的文件 (!-newer test.txt)
- 将找到的所有文件复制到存档目录 (-exec ...)
我是 Unix 脚本的新手。对不起,如果这个问题听起来很愚蠢。
我有一个脚本可以将文件从 Landingzone 复制到存档目录。
现在,我想编写一个脚本来检查 test.txt 文件(类似于触发器文件),只有在找到文件后才复制 test.txt 之前到达的所有文件=17=] 文件从 Landingzone 到 Archive。请让我知道该怎么做?
我将其称为脚本是因为除了复制之外我还有更多命令。
这应该有效
ARCHIVE=... # archive directory
cd Landingzone
if [ -f test.txt ]; then
find . -type f -maxdepth 1 ! -name test.txt ! -newer test.txt -exec cp {} $ARCHIVE ';'
fi
说明: 感谢 if [ -f ... ];仅当 test.txt 存在时才会执行所有操作。然后我们调用 find to
- 仅搜索普通文件 ('-f')
- 排除子目录 (-maxdepth 1)
- 排除 test.txt 本身 (!-name test.txt)
- 排除比 test.txt 更新的文件 (!-newer test.txt)
- 将找到的所有文件复制到存档目录 (-exec ...)