[Solved] Messaging data into required report


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Messaging data into required report
# 1  
Old 02-02-2012
[Solved] Messaging data into required report

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

Code:
[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:

Code:
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

Code:
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:

Code:
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

Last edited by radoulov; 02-02-2012 at 04:46 PM.. Reason: Code tags, please!
# 2  
Old 02-02-2012
Hi gvolpini,

Correct me if I'm wrong, but as I understand the problem is with the format of the output data.

This could be a solution, adapt it to your source. I assume that infile has the CSV content of your script, and next program prints it as you wish.
Code:
$ cat infile
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
$ cat script.pl
use warnings;
use strict;

my (%client_data, $num_clients);

while ( my $line = <> ) {
        my ($rule, $client) = split /,/, $line;
        ++$num_clients;
        push @{ $client_data{ uc $client } }, $rule;
}


printf qq[Rules changed for %d clients: %s\n], 
                $num_clients, 
                join qq[, ], 
                        map { 
                                @{ $client_data{ $_ } } > 1 ? 
                                        $_ . qq[ x] . scalar @{ $client_data{ $_ } } 
                                                : 
                                        $_ } 
                                keys %client_data;

printf qq[The total number of Rules changed are: %d\n], $num_clients;

for ( keys %client_data ) {
        printf qq[Rules changed for %s: %s\n], 
                $_, 
                join qq[, ], @{ $client_data{ $_ } };
}

$ perl script.pl infile
Rules changed for 5 clients: QSC, FID, GJV, BNS x2
The total number of Rules changed are: 5
Rules changed for QSC: 51176
Rules changed for FID: 120008
Rules changed for GJV: 120006
Rules changed for BNS: 120004, 120007

Regards,
Birei
# 3  
Old 02-03-2012
Thanks birei...will give it a try !!

---------- Post updated at 11:00 AM ---------- Previous update was at 10:26 AM ----------

Worked like a charm..I just had to add the initial file open as I am not sending the source file as a parameter....thanks SO MUCH !!!

I new that this could only really be done with arrays however I have not yet reached that level of understanding of coding arrays.

Regards
Giuliano
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fetching the required data out of a tabular form

Hello Gurus, I am trying to fetch a required number of lines from an output of a command which is in tabular form. Below is the command for reference along with how the result is being shown on UNIX shell. /usr/openv/volmgr/bin/vmquery -b -p 5 The result of the above command is as... (6 Replies)
Discussion started by: Ali Sarwar
6 Replies

2. Shell Programming and Scripting

Help Need to fetch the required data

Hi Guys, Am in need of your help one more time on my real data. I have a file which contains more than thousand lines of data Live data shown for 4 iterations. We have more than thousand lines of data:- -------------------------------------------------------------------------- ... (4 Replies)
Discussion started by: rocky2013
4 Replies

3. Shell Programming and Scripting

Need to cut a some required data from file

Data_Consolidation_Engine_Part_2_Job2..TgtArBkt: ORA-00942: table or view does not exist I have some thing like above in the file.. Upto this portion Data_Consolidation_Engine_Part_2_Job2..TgtArBkt: the length can be vary .. Can some one help me in taking this portion alone ORA-00942:... (7 Replies)
Discussion started by: saj
7 Replies

4. Shell Programming and Scripting

List no. of files in a directory/sub dir's and also an consolidated report as required

Need help on below query asap. Thanks. The below is the directory structure: /home/suren under /suren the following are the directories /bin /log /error /bin contains the following files abc.txt bcd.ksh cde.sh wer.ksh ghi (file with out any extension) /log contains the following... (1 Reply)
Discussion started by: sureng
1 Replies

5. Shell Programming and Scripting

Perl script required for processing the data

I have following result.log file (always has 2 lines) which I need to process, cat result.log name.cmd.method,"result","abc","xyz"; name="hello,mine.12345,"&"tree"&" xyz "&" tree "&" xyz", data="way,"&" 1"&"rate-me"&"1"&"rate-me",str="",ret=""; now I need to extract the strings/data as... (4 Replies)
Discussion started by: perlDiva
4 Replies

6. UNIX for Dummies Questions & Answers

[Solved] Packages required - Libaio.so.1 - Libstdc++so.6

hi guys I have to install a software that says have theses packages are required Libaio.so.1 Libstdc++so.6 are these default packages for a Suse 11 installation for instance? or do I need to download them to avoid dependency issues thanks a lot ---------- Post updated at 10:00 PM... (0 Replies)
Discussion started by: kopper
0 Replies

7. UNIX and Linux Applications

Get the data in my required form using gawk

i had the data in the following form: Branch : 3379 As On : 31-JAN-2009 Page : 1 User Id : OPER1 Date & Time : 01-FEB-2009 04:02:37 ... (2 Replies)
Discussion started by: KANNI786
2 Replies

8. UNIX for Advanced & Expert Users

sort out the required data

Hi All, I have a file 1.txt which has the duplicate dns entries as shown: Name: 000f9fbc6738.net.in|Addresses: 10.241.66.169, 10.84.2.222,212.241.66.170 Name: 001371e8ed3e.net.in|Addresses: 10.241.65.153, 10.84.1.101 Name: 00e06f5bd42a.net.in|Addresses: 10.72.19.218,... (6 Replies)
Discussion started by: imas
6 Replies

9. Shell Programming and Scripting

grep required data from two columns

hello, I have output from a command and I need to filter some info out of that. I tried awk command but I can not grep what I am looking for: Following is the output and I need to capture "disabled" for each volume from first column and report: # vol status Volume State ... (2 Replies)
Discussion started by: za_7565
2 Replies

10. Shell Programming and Scripting

Help required with a Csh script to read data from a file

Dears, This is what i want.. I need to read a comma separated text file whose name is config.txt. whose content is like ; bscnara,btserrr bscsana,btssanacity ..... i need to read the first string and second string and use it to execute a another shell script. This is the logic. ... (1 Reply)
Discussion started by: fizzme
1 Replies
Login or Register to Ask a Question