免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5849 | 回复: 7
打印 上一主题 下一主题

perl cgi 表格中的link问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-08 22:56 |显示全部楼层 |倒序浏览
15可用积分
-----------------------------------------------------------------------------------------------
|                          |                   |                  |                     |                            |      
|        DATE            |    OS TYPE  |  IP             |    COMMAND|     RESULTS          |
|________ _______| ____________________________________________ ___________|
|                          |                   |                  |                     |                             |
|                          |                   |                  |      comd1         |       false                |
|                          |                   |                  |                     |                            |
| ______________ |_________________________________________________________  |
|                          |                   |                  |                     |                            |
|                          |                   |                  |     comd2           |     true                 |
|                          |                   |                  |                     |                            |
-----------------------------------------------------------------------------------------------

下面的cgi 程序 是生成 上面表格的代码。

#!/usr/bin/perl
use strict;
use warnings;

use CGI ;
use HTML::Template;
use IO::File;

my $tmpl_file = '/var/www/cgi-bin/tmplate';  # Change it
my $data_file = '/var/www/cgi-bin/log/testlog';  # Change it

my $template = HTML::Template->new(filename => $tmpl_file);
my $file = IO::File->new($data_file);

my $q = CGI->new;

my @data = $file->getlines;

my %dates = ();
for (@data) {
#        $dates{(split /:/, (split)[0])[0]} = 1;
        $dates{(split /:/)[0]} = 1;
}

my @dates = sort keys %dates;
my $selected = $q->param('rundate') || pop @dates;
@dates = map { {date => $_} } @dates;



my @log;


for (@data) {
        my %t;
        @t{qw/date computer platform command result Detail/} = (split(/;;/));
       if ($t{result} eq 'FALSE') {
           $t{result} = '<font color="red"> <a href=\'/cgi-bin/first.pl\' />' .$t{result}.'</font>';
       }elsif ($t{result} eq 'TRUE') {
           $t{result} = '<font color="green">'.$t{result}.'</font>';
       }
        push @log, \%t if $t{date} =~ /$selected/;

}
$template->param(selected        => $selected,
                                 log                => \@log,
                                 dates                => \@dates);

print $q->header, $template->output;

其中log文件是shell脚本自动生成的。
格式如下
2009/01/05:14:42:21;;Redhat5.1;;12;;COMD1;;FALSE;;YT10A
2009/01/05:14:42:44;;Redhat5.1;;12;;COMD2;;TRUE;;102A
2009/01/05:14:42:46;;Redhat5.1;;62;;COMD3;;TRUE;;H02A


这段中是如果是falus,点false就是链接到一个文件
  $t{result} = '<font color="red"> <a href=\'/cgi-bin/first.pl\' />' .$t{result}.'</font>';

现在的问题我点false 只能link到一个固定的地方, 但在log文件中, 每个false link的应该是不同的地方。这个怎么做到呢?
如我
第一行false ,点false 应该指向一个错误文件comd1.err,
第三行false,  点 false 应该指向另一个错误文件comd3.err,

这个错误的文件名应该和第四列comand有关系,
这样如何实现???

[ 本帖最后由 huanghaojie 于 2009-1-8 23:00 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2009-01-08 23:23 |显示全部楼层
是的,tmplate如下,没变。这是工作的东东,所以还得给点积分出来才心安,呵呵,刚学perl有一个星期多了,对这个还是不太熟悉, 还得请高手帮忙, 谢谢ynchnluiti了先。


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <meta http-equiv="Content-Type" content="text/html; charset=gbk">
  <TITLE> Log </TITLE>
  <script>
     function dosubmit(dateobj) {
            dateobj.form.submit();
     }
  </script>
</HEAD>
    <table align=center>
          <td><b>Hatteras CLI Automation Test Results</b> </td>
    </table>

<BODY>

<div align="right">
<form>
<select name="rundate" onChange="dosubmit(this);">
<option value=<tmpl_var name="selected"> selected><tmpl_var name="selected"></option>
<tmpl_loop name="dates">
<option value=<tmpl_var name="date"> ><tmpl_var name="date"></option>
</tmpl_loop>

</select>
</form>
</div>


  <table border="1" width="900" align=center bordercolor="#6595d6">
    <tr>
      <th align=center id=tabletitlelink height=25 width="20%" style="font-weight:normal"><b>Test Date</b></th>
      <th align=center id=tabletitlelink height=25 width="15%" style="font-weight:normal"><b>System Type</th>
      <th align=center id=tabletitlelink height=25 width="10%" style="font-weight:normal"><b>HostName</th>
      <th align=center id=tabletitlelink height=25 width="30%" style="font-weight:normal"><b>System Command</th>
      <th align=center id=tabletitlelink height=25 width="10%" style="font-weight:normal"><b>Results</th>
      <th align=center id=tabletitlelink height=25 width="15%" style="font-weight:normal"><b>Hatteras Version</th>
    <tr>
  <tmpl_loop name="log">
        <tr>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=date></td>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=computer></td>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=platform></td>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=command></td>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=result></td>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=Detail></td>
        </tr>
  </tmpl_loop>
  </table>
</BODY>
</HTML>

论坛徽章:
0
3 [报告]
发表于 2009-01-08 23:55 |显示全部楼层
原帖由 ynchnluiti 于 2009-1-8 23:40 发表

for (@data) {
    my %t;
    @t{qw/date computer platform command result Detail/} = (split(/;;/));

    if ($t{result} eq 'FALSE') {
        #$t{result} = ' ' .$t{result}.'';
        $t{r ...


oh, 非常感谢ynchnluiti,  
忘记说一下, COMD1,COMD3 也是由几部分组成 如COMD1实际上是 cli mkgp -p profile    ,COMD3 是 cli rmgp -f file ,但这些都是由空格分隔,由第二个域+.err 构成  error文件的, 第一个是mkgp.err ,第三个是rmpg.err.

论坛徽章:
0
4 [报告]
发表于 2009-01-09 10:08 |显示全部楼层
原帖由 ynchnluiti 于 2009-1-8 23:45 发表
这个得到的连接是
FALSE

你可以修改

红色部分,改为对应的链接文件名。


把红色部分再分隔,怎么作呀  COMD1 是要再分隔的,

论坛徽章:
0
5 [报告]
发表于 2009-01-09 10:33 |显示全部楼层
谢谢, 新问题
my $data_file = '/var/www/cgi-bin/log/testlog';  # Change it
这是一个log文件,这个log文件是放在服务器上,如果同时有很多机器往这个log里写文件可能会出问题,现在这里有三种系统aix,linux,windows, 我要有三个log文件的话,这个cgi怎么改。

论坛徽章:
0
6 [报告]
发表于 2009-01-09 11:15 |显示全部楼层
刚才又仔细想了一下, 想这样会好点
1. my $data_file = '/var/www/cgi-bin/log/testlog' 这样现在是一个log文件
我想把log做成一个目录my $data_file = '/var/www/cgi-bin/log/ ,登录 IP/cgi-bin/log后 能看到里面有很多log file,这样每个人就可以打开自己想要的log

2 这样的话,cgi如何改? 如果这样改了后, 可能就会对我上面问的那个 false的link有影响, 因为之前是一个固定的log file,可以取每个file command域的error, 但现在是很多log file, 动态的去取log file的command域的error.

不过可以慢慢来,先解决第一个问题

论坛徽章:
0
7 [报告]
发表于 2009-01-09 16:23 |显示全部楼层
怎么改cgi呢

论坛徽章:
0
8 [报告]
发表于 2009-01-10 19:35 |显示全部楼层
现在想有两级页面,第一级是log file name.
如:
162logs
163logs
164logs
165logs
***

但这些file name都是link,怎么写cgi
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP