如何在 Windows XP 上使用 Perl 归档 .log 文件?
以尽可能简单的方式,我想知道是否有人知道如何通过简单地使用当前的“localtime()”作为文件名的一部分来命名它们,从而将 .log 文件存档在 Windows XP 目录中? (不要假设日志文件上有锁。)我尝试了各种不同的方法来执行此操作,但无法解决它......并且网络上没有好的示例。
这是我正在寻找的:
for (all files > that 1 day old)
rename file to file.[datestamp].log
end
In as simple a way as possible I am wondering if anyone knows how to archive .log files in a Windows XP directory by simply naming them with the current "localtime()" as part of the file name? (Do not assume there is a lock on the log file.) I tried all kinds of different ways of doing this but couldn't solve it... and there are no good examples on the web.
Here is what I am looking for:
for (all files > that 1 day old)
rename file to file.[datestamp].log
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
嗯,这看起来很简单,我可能误解了一些东西。任务是将例如“yada.log”移动到“yada.2011-05-04.log”?那么这个怎么样:
Well, this looks so easy, I'm probably misunderstanding something. The task is to move for example "yada.log" to "yada.2011-05-04.log"? Then how about this:
这就是我最终是如何做到的,感谢 TLP!该脚本在第 12 行有错误,但几乎无法工作。
Here is how I ultimately did it, thanks to TLP ! This script is buggy on line #12 but it barely works.
也许有一些模块可以为您执行此操作,例如
Logfile::Rotate例如。
Perhaps there are some modules that can do this for you, somehting like
Logfile::Rotate
for example.