CAMEL 正在处理“mv”之前的文件。命令完成
我们的监控脚本遇到了问题。
程序的流程是
- 客户 ftp/sftp 将文件(.csv 格式)传输到“源”目录
- Bash 脚本将完成的 .csv 文件重命名为 .aaa 文件
- 另一个 Bash 脚本将“.aaa”文件移动到“目标”目录并将文件重命名回“.csv”
- CAMEL 正在监视“目标”目录。如果任何文件到达“目标”文件夹并且扩展名不等于“.aaa”,它将开始处理该文件。
这里第 3 步失败了。 Bash 脚本成功移动文件。但是,当将文件从“.aaa”重命名为“.csv”时,CAMEL 会获取文件并开始处理。 CAMEL 失败并出现错误“页脚不存在”。这是因为“mv”命令未完成,并且 CAMEL 在“mv”完成之前进行了处理。所以它处理了一个不完整的文件。
由于我们使用脚本,因此在使用命令时几乎没有灵活性。我们使用Linux“mv”命令来重命名该文件。
有没有办法在重命名时锁定脚本中的文件,从而阻止 CAMEL 访问它?
或者有更好的方法来处理这种情况吗?
提前感谢您的帮助。
谢谢, 马修·李居
We are facing a problem in our monitor script.
The flow of the program is
- Customer ftp/sftp the file (in .csv format) to "source" directory
- Bash script renames the completed .csv file to .aaa file
- Another Bash script moves the ".aaa" file to "destination" directory and renames the file back to ".csv"
- CAMEL is monitoring the "destination" directory. If any file comes to "destination" folder and having extension not equal to ".aaa" it will start processing the file.
Here the step 3 is failing. Bash script moves the file successfully. But while renaming the file from ".aaa" to ".csv" CAMEL fetches the file and start processing. CAMEL fails with the error "the footer is not present". This is because the "mv" command was not complete and CAMEL processed before the "mv" is completed. So it processed an incomplete file.
Since we use scripting we have little flexibility in using the commands. We are using Linux "mv" command to rename the file.
Is there a way to lock the file in scripting while renaming which will stop the CAMEL from accessing it?
Or is there a better way of handling this scenario?
Appreciate the help in advance.
Thanks,
Mathew Liju
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第3步怎么做?
或者
我认为后者应该是原子的,而如果 origin 和 dest 位于不同的分区/文件系统上,则第一个是副本。
How do you do step 3?
or
The latter should be atomic I think, while the first is a copy if origin and dest are on different partitions / filesystems.
我不知道 CAMEL 是什么,但我认为您正在文件系统上寻找无锁队列机制。 Maildir(qmail的一部分)实现了这样一个无锁的邮件传递队列。
您还可以查看inotify。
根据您的操作系统和分区布局,需要 cp、mv 或 ln 文件。
I don't know what CAMEL is, but i think you are looking for a lock-free queue mechanism on the file system. Maildir (part of qmail) implements such a lock-free mail delivery queue.
You can also have a look all around inotify.
Depending on your OS and partition layout it would be necesary to cp, mv or ln the files.
一个好的提示是始终写下您正在使用的各种产品的版本。
无论如何,Camel 2.x 有 5 个左右不同的读锁选项,您可以从中选择来解决此类问题。如果您有特殊的支持,例如人们必须仅在有特殊的 .DONE 文件时才开始读取文件等,您可以实现自己的。
http://camel.apache.org/file2.html
A good tip is to always write what version of the various products you are using.
Anyway Camel 2.x got 5 or so different readlock options you can choose from to remedy such an issue. And you can implement your own if you have special supports such as people having to only start reading files if there is a special .DONE file etc.
http://camel.apache.org/file2.html