Folks,
I am a software developer and I have a written a script which will read the
configuration like to address, subject of the mail and the threshold value.
After reading the three values from the config file i will query the
database and the result of the query i am genearting a report and the same
report i am sending the same as mail. This script works fine at my end, if i
execute the same at different machine situated at different place. I am not
getting the values, A small part of program i will send it you guys just
help me,
PGM :
#!/usr/bin/perl
#
use DBI;
#
# Variables
#
$mysql_db_host = "Host"; # MySQL Host
$mysql_db_port = "Port"; # MySQL Port
$mysql_db_user = "username"; # MySQL User
$mysql_db_pass = ""; # MySQL Pass
$config_file = "/u01/pix/config.txt"; # Config File
$date=`date +%Y%m%d`;
$date=~s/\n//g;
$tHr=`date +%H`;
$tM=`date +%M`;
$tS=`date +%S`;
$temp=$tM-30;
if ($temp<0)
{
$tHr=$tHr-1;
$tM=60-$tM;
}
else
{
$tM=$tM-30;
}
$tDate=`date +%Y'-'%m'-'%d`;
$tFrom=join "",$tDate," ",$tHr,":",$tM,":",$tS;
$tFrom =~ s/\n+//g;
$tTo=`date +%Y'-'%m'-'%d' '%H':'%M':'%S`;
open(FILE,"<$config_file");
while (<FILE>) {
$line = $_;
if ($line =~ /(.*)To :(.*)/)
{
($tmp,$ToMail)=split("To :",$line);
}
if ($line =~ /(.*)Subject :(.*)/)
{
($tmp,$MailSubject)=split("Subject :",$line);
}
if ($line =~ /(.*)Threshold :(.*)/)
{
($tmp,$threshold)=split("Threshold :",$line);
}
}
&db_select();
sub db_select
{
my $dbh =
DBI->connect("DBI:mysql:database=pix;host=$mysql_db_host;port=$mysql_db_port",$mysql_db_user,$mysql_db_pass)
or die "Couldn't connect to database: $DBI::errstr\n";
my $del=qq{drop table temp};
$delsth=$dbh->prepare($del);
$delsth->execute();
my $sql=qq{create table temp SELECT log_time, log_resource, log_src_dir,
log_src_ip, log_src_pt, log_dst_dir, log_dst_ip,log_dst_pt, count(1) as
CountHit FROM traffic_log where log_time between \'$tFrom\' and \'$tTo\'
group by log_resource, log_src_dir,log_src_ip, log_src_pt,
log_dst_dir,log_dst_ip,log_dst_pt order by 8 desc, 1,2,3};
my $sth=$dbh->prepare($sql);
$sth->execute();
my $sql1=qq{select * from temp order by CountHit desc limit 15};
my $sth1=$dbh->prepare($sql1);
$sth1->execute();
my( $logtime,$res, $srcdir,$srcip, $srcpt,$dstdir,$dstip,$dstpt,$count );
$sth1->bind_columns( undef,\$logtime,\$res,
\$srcdir,\$srcip,\$srcpt,\$dstdir,\$dstip,\$dstpt,\$count );
$header="PRO-ACTIVE REPORT GENERATED AT ".$tTo;
open(FILEH,">/u01/pixscritps/mail.txt") or die "$!";
format MYF1=
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$header
------------------------------------------------------------------------------------------------------------------------------
Date Time | Resource | Source | Source IP | SRC Port | Dest | Dest IP | DST
port | Hits
------------------------------------------------------------------------------------------------------------------------------
.
select(FILEH);
$~="MYF1";
write(FILEH);
format MYF=
@<<<<<<<<<<<<<<<<<<|@<<<<<<<<<< | @<<<<<<< | @<<<<<<<<<<<<<< | @<<<<<<< |
@<<<<<<< | @<<<<<<<<<<<<<< | @<<<<<<< | @>>>>>
$logtime,$res, $srcdir,$srcip, $srcpt,$dstdir,$dstip,$dstpt,$count
------------------------------------------------------------------------------------------------------------------------------
.
while( $sth1->fetch() )
{
select(FILEH);
$~="MYF";
write(FILEH);
}
$sth->finish();
$sth1->finish();
$delsth->finish();
$dbh->disconnect();
#close(FILEH);
$send=qq{cat "/u01/pixscritps/mail.txt" | mail -s $MailSubject :$ToMail};
$send=~s/\n.//;
print $send,"\n"; -- This i have printed to send you that the values in
$MailSubject and $To Mail is not getting printed
#system ($send);
}
######## The output in the file mail.txt is
PRO-ACTIVE REPORT GENERATED AT 2005-10-20 11:08:31
------------------------------------------------------------------------------------------------------------------------------
Date Time | Resource | Source | Source IP | SRC Port | Dest | Dest IP | DST
port | Hits
------------------------------------------------------------------------------------------------------------------------------
2005-10-20 10:52:30|10.20.1.2 | inside | 10.20.1.199 <http://10.20.1.199> |
1282 | outside | 128.8.10.90 <http://128.8.10.90> | 53 | 6354
------------------------------------------------------------------------------------------------------------------------------
2005-10-20 10:52:30|10.20.1.2 | inside | 10.20.1.199 <http://10.20.1.199> |
1282 | outside | 192.203.230.10 <http://192.203.230.10> | 53 | 6345
------------------------------------------------------------------------------------------------------------------------------
2005-10-20 10:52:30|10.20.1.2 | inside | 10.20.1.199 <http://10.20.1.199> |
1282 | outside | 202.12.27.33 <http://202.12.27.33> | 53 | 5827
------------------------------------------------------------------------------------------------------------------------------
2005-10-20 10:52:30|10.20.1.2 | inside | 10.20.1.199 <http://10.20.1.199> |
1282 | outside | 128.9.0.107 <http://128.9.0.107> | 53 | 5826
------------------------------------------------------------------------------------------------------------------------------
2005-10-20 10:52:30|10.20.1.2 | inside | 10.20.1.199 <http://10.20.1.199> |
1282 | outside | 192.33.4.12 <http://192.33.4.12> | 53 | 5724
------------------------------------------------------------------------------------------------------------------------------
2005-10-20 10:52:30|10.20.1.2 | inside | sanforest | 1126 | outside |
128.8.10.90 <http://128.8.10.90> | 53 | 4413
------------------------------------------------------------------------------------------------------------------------------
2005-10-20 10:52:30|10.20.1.2 | inside | sanforest | 1126 | outside |
192.203.230.10 <http://192.203.230.10> | 53 | 4408
------------------------------------------------------------------------------------------------------------------------------
2005-10-20 10:52:30|10.20.1.2 | inside | sanforest | 1126 | outside |
128.9.0.107 <http://128.9.0.107> | 53 | 4350
------------------------------------------------------------------------------------------------------------------------------
2005-10-20 10:52:30|10.20.1.2 | inside | sanforest | 1126 | outside |
192.33.4.12 <http://192.33.4.12> | 53 | 4337
------------------------------------------------------------------------------------------------------------------------------
2005-10-20 10:52:30|10.20.1.2 | inside | sanforest | 1126 | outside |
202.12.27.33 <http://202.12.27.33> | 53 | 4185
------------------------------------------------------------------------------------------------------------------------------
2005-10-20 10:52:31|10.20.1.2 | inside | sanforest | 1126 | outside |
198.41.0.4 <http://198.41.0.4> | 53 | 1017
------------------------------------------------------------------------------------------------------------------------------
2005-10-20 10:52:31|10.20.1.2 | inside | 10.20.1.199 <http://10.20.1.199> |
1282 | outside | 198.41.0.4 <http://198.41.0.4> | 53 | 846
------------------------------------------------------------------------------------------------------------------------------
2005-10-20 10:52:30|10.20.1.2 | inside | 10.1.3.0 <http://10.1.3.0> | |
outside | 216.136.173.161 <http://216.136.173.161> | | 107
------------------------------------------------------------------------------------------------------------------------------
2005-10-20 10:52:30|10.20.1.2 | inside | 10.6.1.220 <http://10.6.1.220> | |
outside | 204.71.200.34 <http://204.71.200.34> | | 105
------------------------------------------------------------------------------------------------------------------------------
2005-10-20 10:52:34|10.20.1.2 | inside | 10.1.3.0 <http://10.1.3.0> | |
outside | 216.136.173.162 <http://216.136.173.162> | | 102
------------------------------------------------------------------------------------------------------------------------------
cat "/u01/pixscritps/mail.txt" | mail -s
Thank in Advance
Regards
Mazhar
Wipro