Hello to all;
hope someone can assist me in getting the required output that my manager is expecting.
I have been able to generate this code which does the comparison of the files and creates the file called diff_fuss_file.txt
[dslgvol@rua ~]$ vi fussrpt.pl
#!/usr/bin/perl
#cd /tmp
#rm output.txt
# PERL MODULES USED
#use strict;
use warnings;
use DBI;
use DBD::mysql;
# CONFIG VARIABLES
my $DB='ops_filetransfer';
my $HOST='pele';
my $user='dslops';
my $pass='dslops72';
my $table='lsof_conf';
# my VARIABLES
my $myfile="/tmp/fuss_lsof_conf.txt";
my $mydiff_file="/tmp/diff_fuss__file.txt";
# PERL DBI CONNECT
my $dbh=DBI->connect( "DBI:mysql:database=$DB;host=$HOST;", $user, $pass) or die "$!\n";
# PREPARE\CONSTRUCT THE QUERY
my $sth=$dbh->prepare("SELECT id, t_client, t_filelocation, t_remotescript, t_destination, t_enabled, t_search, t_compression FROM $table") or die "$!\n";
# EXECUTE THE QUERY
$sth->execute();
#OPEN OUTPUT FILE AND WRITE EACH FETCHED ROW FROM THE DATABASE INTO IT WITH A NEW LINE RETURN AFTER EACH RECORD
open(FH, ">$myfile") or die "$!\n";
while (my @row=$sth->fetchrow_array()) {
print FH join(",", @row)."\n";
}
#CLOSE OUTPUT FILE AND TERMINATE DB CONNECTION
close FH;
$sth->finish();
$dbh->disconnect();
$nmofchgs = `more /tmp/diff_fuss__file.txt | wc -l`;
print "Total number of rules changed or added: $nmofchgs\n";
open (FILE, '/tmp/diff_fuss__file.txt');
while (<FILE>) {
chomp;
($rule, $client) = split("\,");
print " Client: $client\n";
print " Rule: $rule\n";
print "\n";
}
close (FILE);
============================
Data is in a file called diff_fuss_file.txt
Data is csv and here's a sample:
51176,qsc,/ureports/fusqsc/stmt,/home/dslmain/qsc/scripts/copylsoftosftpwithmove.sh,qscsftp@sftp1: prod/qsc/dsi/xml,EXPORT,<where>7862<any>DSI<any>.xml,YES
120004,bns,dslmain@faunus:import/svc,/home/dslmain/bns/scripts/copylsoffromsftpnomove.sh,/ureports/exportbns/svc,IMPORTNOMOVE,<where>fndmut<any>.svc,NO
120006,gjv,/ureports/exportbns/extracts/sent,/home/dslmain/bns/scripts/copylsoftosftp.sh,bnssftp@sftp1: prod/bns/export/extracts,NO,<where><any><yesterday>,NO
120007,bns,dslmain@faunus:import/svc,/home/dslmain/bns/scripts/copylsoffromsftpnomove.sh,/ureports/exportbns/svc,IMPORTNOMOVE,<where>fndmut<any>.svc,NO
120008,fid,/ureports/ibfid/jot/rpts/nofiche,/home/dslmain/fid/scripts/copylsoftosftp.sh,fidsftp@sftp1: prod/fid/jot/rpts/nofiche,YES,<where><any><yesterday><any>,NO
My output looks like this:
Total number of rules changed or added: 5
Client: qsc
Rule: 51176
Client: bns
Rule: 120004
Client: gjv
Rule: 120006
Client: bns
Rule: 120007
Client: fid
Rule: 120008
However my manager prefers this:
Rules rules changed for 5 clients: QSC, BNS x2, GJV, FID
The total number of Rules changed are: 5
Rules changed for QSC: 51176
Rules changed for BNS: 120004, 120007
Rules changed for GJV: 120006
Rules changed for FID: 120008
And finally he wants this saved in a file called fuss_audit_<insert run date>
Fairly new to Perl...thanks in advance for any and all suggestions\solutions.
Sincerely
Giuliano