免费注册 查看新帖 |

Chinaunix

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

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 编辑 ]

论坛徽章:
3
戌狗
日期:2014-09-10 17:07:162015年辞旧岁徽章
日期:2015-03-03 16:54:15wusuopu
日期:2016-06-17 17:43:45
2 [报告]
发表于 2009-01-08 22:56 |只看该作者

回复 #6 huanghaojie 的帖子

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

  4.     if ($t{result} eq 'FALSE') {
  5.         #$t{result} = '<font color="red"> <a href=\'/cgi-bin/first.pl\' />' .$t{result}.'</font>';
  6.         $t{result} = '<font color="red"> <a href=\'/cgi-bin/'.(split(/\s/, "$t{command}"))[1].'.err\' />' .$t{result}.'</a></font>';
  7.     } elsif ($t{result} eq 'TRUE') {
  8.         $t{result} = '<font color="green">'.$t{result}.'</font>';
  9.     }
  10.     push @log, \%t if $t{date} =~ /$selected/;
  11. }
复制代码

论坛徽章:
3
戌狗
日期:2014-09-10 17:07:162015年辞旧岁徽章
日期:2015-03-03 16:54:15wusuopu
日期:2016-06-17 17:43:45
3 [报告]
发表于 2009-01-08 23:17 |只看该作者
tmplate 还是以前那个吗?

论坛徽章:
0
4 [报告]
发表于 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>

论坛徽章:
3
戌狗
日期:2014-09-10 17:07:162015年辞旧岁徽章
日期:2015-03-03 16:54:15wusuopu
日期:2016-06-17 17:43:45
5 [报告]
发表于 2009-01-08 23:40 |只看该作者

回复 #1 huanghaojie 的帖子

[code]
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>';
        $t{result} = '<font color="red"> <a href=\'/cgi-bin/'."\L$t{command}".'.err\' />' .$t{result}.'</a></font>';
    } elsif ($t{result} eq 'TRUE') {
        $t{result} = '<font color="green">'.$t{result}.'</font>';
    }
    push @log, \%t if $t{date} =~ /$selected/;

}code]

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

论坛徽章:
3
戌狗
日期:2014-09-10 17:07:162015年辞旧岁徽章
日期:2015-03-03 16:54:15wusuopu
日期:2016-06-17 17:43:45
6 [报告]
发表于 2009-01-08 23:45 |只看该作者

回复 #4 ynchnluiti 的帖子

这个得到的连接是
  1. <td align=center id=tabletitlelink height=25 style="font-weight:normal"><font color="red"> <a href='/cgi-bin/
  2. comd1.err' />FALSE</a></font></td>
复制代码


你可以修改
$t{result} = '<font color="red"> <a href=\'/cgi-bin/'."\L$t{command}".'.err\' />' .$t{result}.'</a></font>';

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

论坛徽章:
0
7 [报告]
发表于 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
8 [报告]
发表于 2009-01-09 10:08 |只看该作者
原帖由 ynchnluiti 于 2009-1-8 23:45 发表
这个得到的连接是
FALSE

你可以修改

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


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

论坛徽章:
3
戌狗
日期:2014-09-10 17:07:162015年辞旧岁徽章
日期:2015-03-03 16:54:15wusuopu
日期:2016-06-17 17:43:45
9 [报告]
发表于 2009-01-09 10:25 |只看该作者

回复 #8 huanghaojie 的帖子

就是这个:
  1. (split(/\s/, "$t{command}"))[1]
复制代码

论坛徽章:
0
10 [报告]
发表于 2009-01-09 10:33 |只看该作者
谢谢, 新问题
my $data_file = '/var/www/cgi-bin/log/testlog';  # Change it
这是一个log文件,这个log文件是放在服务器上,如果同时有很多机器往这个log里写文件可能会出问题,现在这里有三种系统aix,linux,windows, 我要有三个log文件的话,这个cgi怎么改。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP