【发布时间】:2014-05-21 19:04:29
【问题描述】:
有一个 Web 服务器运行多个网站,并配置了每日日志文件轮换。
任务:创建一个 perl 脚本,检查源目录中当前日志文件的列表,并将其与另一个目录中的轮换日志文件列表进行比较。如果昨天的日志没有轮换,脚本必须打印日志文件的名称。
源目录示例:
ls -l /var/log/httpd/logs/*log
-rw-r--r-- 1 root root 0 May 20 00:01 /var/log/httpd/logs/access.log
-rw-r--r-- 1 root root 483652 May 20 12:54 /var/log/httpd/logs/othersite.com_80-access.log
-rw-r--r-- 1 root root 305 May 20 11:51 /var/log/httpd/logs/othersite.com_80-error.log
-rw-r--r-- 1 root root 0 May 20 00:01 /var/log/httpd/logs/error.log
-rw-r--r-- 1 root root 46222 May 20 12:45 /var/log/httpd/logs/www.site.com_8880-access.log
-rw-r--r-- 1 root root 0 May 20 00:01 /var/log/httpd/logs/www.site.com_8880-error.log
带有旋转日志的目录:
ls -l /var/log/httpd/logs/completed/|grep 2014-05-19
-rw-r--r-- 1 root root 20 May 20 00:01 access.log.2014-05-19.gz
-rw-r--r-- 1 root root 107244 May 20 00:01 othersite.com_80-access.log.2014-05-19.gz
-rw-r--r-- 1 root root 9991 May 20 00:01 www.site.com_8880-access.log.2014-05-19.gz
-rw-r--r-- 1 root root 20 May 20 00:01 www.site.com_8880-error.log.2014-05-19.gz
在这种情况下,两个昨天的日志文件不存在\没有轮换:
-rw-r--r-- 1 root root 483652 May 20 12:54 /var/log/httpd/logs/othersite.com_80-access.log
-rw-r--r-- 1 root root 305 May 20 11:51 /var/log/httpd/logs/othersite.com_80-error.log
期待任何建议!
【问题讨论】:
-
问题是我的Perl知识很差,不知道应该怎么做。我可以使用 Bash 脚本轻松完成,但任务需要 Perl。就是这样。
-
那我先学perl吧。
标签: perl