简体   繁体   English

无法通过perl File :: Tail读取文件

[英]Unable to read file by perl File::Tail

i am trying to get realtime tail of a nginx log file using perl CGI. 我正在尝试使用perl CGI获取nginx日志文件的实时尾部。 i have given permission to file is 644. my perl cgi code is as follows: 我已授予文件为644的权限。我的perl cgi代码如下:

#!/usr/bin/perl
use CGI;
use File::Tail;

print "Content-type: text/html\n\n";

$| = 1; #set auto flush on

# param for specifying number of lines to tail.
#$n =  CGI::param('n');
$n = '20';
$file_name = "/var/log/nginx/access.log";

#show 100 lines by default
$tail = $n?$n:100;

# specifying default as of now
$file_name = $file_name?$file_name:"$file_name";

# tail -n <tail_lines>. Start with tail_lines
$tail_lines=10;

$tail_file=File::Tail->new(name=>$file_name,
                            maxinterval=>2,
                            adjustafter=>1,
                            maxbuf=>16384,
                            tail=>$tail_lines);


while (defined($readline=$tail_file->read))
{
    print $readline."</br>";
}

i have given permission to as follows 我已获准如下

-rw-r--r--. -rw-R - R--。 1 nginx nginx 32565 Jan 7 17:17 /var/log/nginx/access.log 1 nginx nginx 32565 1月7日17:17 /var/log/nginx/access.log

and i am facing this problem with tailf only.............. 而且我只用tailf面对这个问题..............

permission related in nginx log Nginx日志中相关的权限

[Tue Jan 07 17:16:07 2014] [error] [client 127.0.0.1] Error opening /var/log/nginx/access.log: Permission denied at /var/www/cgi-bin/clarity.pl line 32, referer: http://host:8888/clarity.html

help me out from this problem...? 帮助我摆脱这个问题...?

Have you set something up such that the perl CGI script runs as a separate user? 您是否进行了某些设置,以使perl CGI脚本作为单独的用户运行?

Typically most modern nginx installations have scripts executing as a different user. 通常,大多数现代的nginx安装都有以不同用户身份执行的脚本。 This way if someone hacks into your CGI script, they cannot easily affect the actual web server process. 这样,如果有人侵入您的CGI脚本,他们就不会轻易影响实际的Web服务器进程。

You can try something like 您可以尝试类似

print "real uid: $<, effective uid: $>\n";

in a separate CGI script to test what user your script is actually running as. 在一个单独的CGI脚本中以测试您的脚本实际以哪个用户身份运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM