如何在程序执行之间保存数据

发布于 2024-12-04 03:26:32 字数 207 浏览 5 评论 0原文

我正在 HP-UX 机器上运行 perl 脚本。该脚本将每 15 分钟执行一次,并且需要将其结果与上次执行的结果进行比较。

我需要在执行之间存储两个变量(IsOccuring 和 ErrorCount)。最好的方法是什么?

编辑说明:
它仅将最近的执行与当前的执行进行比较。
如果该值在重新启动之间丢失也没关系。
并且接触文件系统几乎是禁止的。

I am running a perl script on a HP-UX box. The script will execute every 15 minutes and will need to compare it's results with the results of the last time it executed.

I will need to store two variables (IsOccuring and ErrorCount) between the executions. What is the best way to do this?

Edit clarification:
It only compares the most recent execution to the current execution.
It doesn't matter if the value is lost between reboots.
And touching the filesystem is pretty much off limits.

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

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

发布评论

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

评论(7

踏雪无痕 2024-12-11 03:26:33

如果您无法触及文件系统,请尝试使用共享内存段。有一些辅助模块,例如 IPC::ShareLite,也可以直接使用shmget及相关函数。

If you can't touch the file system, try using a shared memory segment. There are helper modules for that like IPC::ShareLite, or you can use the shmget and related functions directly.

油饼 2024-12-11 03:26:33

您必须将它们存储在文件中。此类文件通常保存在 /tmp 中,但运行 cron 作业的用户有权访问的任何位置都可以。确保您的脚本可以处理文件丢失的情况。

You'll have to store them in a file. This sort of file is often kept in /tmp, but any place where the user running the cron job has access would do. Make sure your script can handle the case where the file is missing.

葬シ愛 2024-12-11 03:26:33

您可以创建一个单独的进程,在您选择的 IPC 机制上运行“记住内容”服务。这听起来像是“我不想碰磁盘”的一个相当折磨人的解决方案,但如果它足够重要,足以抵消几天的开发工作(实际上,如果您是 IPC 新手,并且 HP-SUX 继续存在)直到它的名字)然后一定要阅读 ma​​n perlipc 作为开始。

You could create a separate process running a "remember stuff" service over your choice of IPC mechanism. This sounds like a rather tortured solution to "I don't want to touch the disk" but if it's important enough to offset a couple of days of development work (realistically, if you are new to IPC, and HP-SUX continues to live up to its name) then by all means read man perlipc for a start.

苏璃陌 2024-12-11 03:26:33

是否必须完全重新执行?您可以让它循环运行并在迭代之间休眠 15 分钟吗?您不必担心在外部保存值,程序永远不会停止。

Does it have to be completely re-executed? Can you just have it running in a loop and sleeping for 15 minutes between iterations? Than you don't have to worry about saving the values externally, the program never stops.

挽清梦 2024-12-11 03:26:33

我绝对认为 IPC 是正确的选择。

I definitely think IPC is the way to go here.

终遇你 2024-12-11 03:26:33

我会将数据保存在文件中。然后,在脚本内,如果文件存在,我将加载最后的结果。

I'd save off the data in a file. Then, inside the script I'd load the last results if the file exists.

无人问我粥可暖 2024-12-11 03:26:33

使用模块Storable来序列化Perl数据结构,将它们保存在任何你想要的地方并反序列化它们在下一个脚本执行期间。

Use module Storable to serialize Perl data structures, save them anywhere you want and deserialize them during next script execution.

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