#!/usr/local/bin/perl
#runs on avazi on oracle environment with user root
#use LWP::Simple;
############################################################################
# Title: GRN_XML_check
# Author: Guy Kane
# Last Update: 24/08/2001
############################################################################
############################################################################
# MAIN
############################################################################
get_GRN ();
put_GRN_in_array ();
check_GRN ();
print_result ();
check_xml ();
############################################################################
sub get_GRN
############################################################################
{
print ("Enter resource ID\n");
$resource = <STDIN>;
chop $resource;
open (FILE, "> qa.sql");
print FILE ("spool qa_grn.sql;\n");
print FILE ("select RESOURCE_ID from PK_RESOURCES where PK_ID = $resource;\n");
print FILE ("spool off;\n");
print FILE ("commit;\n");
print FILE ("exit;\n");
close (FILE);
system ("sqlplus globalsale/informix \@qa.sql");
$data_file="qa_grn.sql";
} ##get_GRN
############################################################################
sub put_GRN_in_array
############################################################################
{
open(DAT, $data_file) || die("Could not open file!");
@qa=<DAT>;
close(DAT);
}
##put_GRN_in_array
############################################################################
sub check_GRN
############################################################################
{
$i=0;
$j=0;
$l=0;
$found=false;
foreach $cell (@qa)
{
$blank =substr($cell, 0, 1);
if ( $blank eq " " )
{
$grn=substr($cell, 8, 3);
$grn_modul=$grn%100;
$found_real = ("/data/var/real/Content/$grn.rm");
$status_real = qx "ls /data/var/real/Content/$grn.rm";
chop ($status_real);
$found_pici = ("/data/var/pici/base/$grn_modul/$grn/file");
$status_pici = qx "ls /data/var/pici/base/$grn_modul/$grn/file";
chop ($status_pici);
$fail = ("/data/var/pici/base/$grn2/$grn1/file: No such file or directory");
if ( $status_real eq $found_real )
{
@real[$i]="$grn";
$found=true;
$i++;
}
else
{
if ( $status_pici eq $found_pici )
{
@pici_base[$j]="$grn";
$j++;
}
else
{
@lost_grn[$l]="$grn";
$l++;
}
}
}
}
}
##check_GRN
############################################################################
sub print_result
############################################################################
{
open (FILE, "> qa_result.sql");
print FILE ("\n");
$i=0;
$j=0;
print FILE ("I_PAC REAL GRN\n");
foreach $cell (@real)
{
print FILE ("$cell\t");
$i++;
$j++;
if ( $i==9 )
{
print FILE ("\n");
$i=0;
}
}
if ( $j==0 )
{
print FILE ("There are no real grn's in this I_PAC\n");
}
print FILE ("\n");
print FILE ("\n");
$i=0;
$j=0;
print FILE ("I_PAC PICI GRN\n");
foreach $cell (@pici_base)
{
print FILE ("$cell\t");
$i++;
$j++;
if ( $i==9 )
{
print FILE ("\n");
$i=0;
}
}
if ( $j==0 )
{
print FILE ("There are no pici grn's in this I_PAC\n");
}
print FILE ("\n");
print FILE ("\n");
$i=0;
$j=0;
print FILE ("I_PAC LOST GRN\n");
foreach $cell (@lost_grn)
{
print FILE ("$cell\t");
$i++;
$j++;
if ( $i==9 )
{
print FILE ("\n");
$i=0;
}
}
if ( $j==0 )
{
print FILE ("All the resources were found for this I_PAC\n");
}
print FILE ("\n");
}
##print_result
############################################################################
sub check_xml
############################################################################
{
$xml = 0;
$resource_modul = $resource%100;
$found_xml = ("/data/var/pici/base/$resource_modul/$resource/file");
$status_xml = qx "ls /data/var/pici/base/$resource_modul/$resource/file";
chop ($status_xml);
if ( $status_xml eq $found_xml )
{
$xml = 1;
}
print FILE ("XML STATUS\n");
if ( $xml == 0 )
{
print FILE ("Xml did not arrive to the pici base\n");
}
else
{
if ( $xml == 1 )
{
$xml_status = qx "grep -c '<SHOWCASE>' /data/var/pici/base/$resource_modul/$resource/file";
if ( $xml_status == 0 )
{
print FILE ("$resource GRN is not an xml file\n");
}
else
{
$right_tag = qx "grep -c '>' /data/var/pici/base/$resource_modul/$resource/file";
$left_tag = qx "grep -c '<' /data/var/pici/base/$resource_modul/$resource/file";
if ( $right_tag != $left_tag )
{
print FILE ("$resource GRN is a corrupt xml file\n");
}
else
{
print FILE ("$resource GRN arrived and appear to be a correct xml file\n");
}
}
}
}
print FILE ("\n");
close (FILE);
system ("more qa_result.sql\n");
}
##check_xml