如何在 Unix 中管理报告/文件分发到不同的目的地?

发布于 2024-08-16 16:53:15 字数 203 浏览 2 评论 0原文

报告工具将在文件系统(Unix 目录)中生成大量报告/文件。有一个目的地列表(电子邮件地址和共享文件夹),其中需要在每个目的地分发一组不同的报告/文件(可以重叠)。

我想知道是否有一种方法可以使用 shell 脚本有效地管理此报告交付,以便将来报告和目标列表的维护不会变得一团糟。

这是一个开放式问题,但限制是它应该在 Unix FS 中管理报告的范围内工作。

The reporting tools will generate a huge numbers of reports/files in the file system (a Unix directory). There's a list of destinations (email addresses and shared folders) where a different set of reports/files (can have overlap) are required to be distributed at each destinations.

Would like to know if there's a way to efficiently manage this reports delivery using shell scripts so that the maintenance of the list of reports and destinations will not become a mess in future.

It's quite an open ended question, the constraint however is that it should work within the boundaries of managing the reports in a Unix FS.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨落□心尘 2024-08-23 16:53:15

您始终可以创建一个简单的文本文件(此处为report_locations.txt),其中包含报告所在的名称/位置,即

ReportName1;/home/bob
ReportName2;/home/jim,/home/jill
ReportName3;/home/jill,/home/bob

报告名称将始终是此示例中的第一个字段以及相应报告应遵循的位置,以逗号(或任何您喜欢的其他分隔符)。

然后用 shell 脚本读取该文件(我喜欢使用 for 循环进行此类操作):

#!/usr/bin/ksh93
for REPORT in $(cut -d";" -f1 report_locations.txt)
do
        LISTS=$(grep ${REPORT} report_locations.txt | cut -d";" -f2)
        for LIST in ${LISTS}
        do
                DIRS=$(echo ${LIST} | tr ',' '\n')
                for DIR in ${DIRS}
                do
                        echo "Copying ${REPORT} to ${DIR}"
                        cp -f ${REPORT} ${DIR}
                done
        done
done

for 循环的使用可能有点过多(我被抓住了),但它完成了工作。

不确定这是否是您想要的,但它是一个起点(如果有的话)。如果您需要代码的任何解释,请随时询问。

You could always create a simple text file (report_locations.txt here) with names/locations where reports go i.e.

ReportName1;/home/bob
ReportName2;/home/jim,/home/jill
ReportName3;/home/jill,/home/bob

The report names will always be the first field in this example and locations where the corresponding reports should go follow, delimited by commas (or any other delimiter you like).

Then read that file with a shell script (I like to use for loops for this sort of operation):

#!/usr/bin/ksh93
for REPORT in $(cut -d";" -f1 report_locations.txt)
do
        LISTS=$(grep ${REPORT} report_locations.txt | cut -d";" -f2)
        for LIST in ${LISTS}
        do
                DIRS=$(echo ${LIST} | tr ',' '\n')
                for DIR in ${DIRS}
                do
                        echo "Copying ${REPORT} to ${DIR}"
                        cp -f ${REPORT} ${DIR}
                done
        done
done

The use of for loops may be a bit excessive (I get caught up in them), but it gets the job done.

Not sure this is what you would be looking for, but it is a starting point if anything. Don't hesitate to ask if you need any explanation of the code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文