LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-29-2006, 08:30 PM   #1
Toadman
Member
 
Registered: Aug 2002
Location: Copperas Cove, Texas
Distribution: Ubuntu 20.04 LTS
Posts: 304

Rep: Reputation: 21
clamav stats perl script help


First of all I'm not perl smart nor am I knowledgable in scripting. I downloaded a perl script for generating clamav stats, the author had not updated it in several years and told me to go ahead and do with it what I could. Through some outside help I got the script to semi-work, however, I get the below errors:

Use of uninitialized value in substitution (s///) at /usr/local/bin/clamstats.pl line 105.
Use of uninitialized value in concatenation (.) or string at /usr/local/bin/clamstats.pl line 106.
Use of uninitialized value in concatenation (.) or string at /usr/local/bin/clamstats.pl line 106.
Use of uninitialized value in concatenation (.) or string at /usr/local/bin/clamstats.pl line 106.
Use of uninitialized value in concatenation (.) or string at /usr/local/bin/clamstats.pl line 106.
Use of uninitialized value in split at /usr/local/bin/clamstats.pl line 108.
Use of uninitialized value in hash element at /usr/local/bin/clamstats.pl line 115.
Use of uninitialized value in hash element at /usr/local/bin/clamstats.pl line 116.
Use of uninitialized value in hash element at /usr/local/bin/clamstats.pl line 117.
Use of uninitialized value in hash element at /usr/local/bin/clamstats.pl line 118.
Use of uninitialized value in hash element at /usr/local/bin/clamstats.pl line 120.
Use of uninitialized value in hash element at /usr/local/bin/clamstats.pl line 122.
Use of uninitialized value in hash element at /usr/local/bin/clamstats.pl line 122.
Use of uninitialized value in hash element at /usr/local/bin/clamstats.pl line 124.
Use of uninitialized value in hash element at /usr/local/bin/clamstats.pl line 124.
Use of uninitialized value in hash element at /usr/local/bin/clamstats.pl line 125.
Use of uninitialized value in hash element at /usr/local/bin/clamstats.pl line 125.
Use of uninitialized value in hash element at /usr/local/bin/clamstats.pl line 49.
Use of uninitialized value in sprintf at /usr/local/bin/clamstats.pl line 49.
Use of uninitialized value in sprintf at /usr/local/bin/clamstats.pl line 49.
Argument "" isn't numeric in sprintf at /usr/local/bin/clamstats.pl line 317.
Use of uninitialized value in sprintf at /usr/local/bin/clamstats.pl line 53.

I see that I can't post attachments. The script is 3.1kb gzip'd, if someone would like to look at the whole script, please let me know.

Thanks
Chris
 
Old 05-30-2006, 12:51 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Posting a few lines of your "/usr/local/bin/clamstats.pl", say from lines 105 - 126, and from lines 49 - 55, might be a good alternative ;-)
 
Old 05-30-2006, 05:15 PM   #3
Toadman
Member
 
Registered: Aug 2002
Location: Copperas Cove, Texas
Distribution: Ubuntu 20.04 LTS
Posts: 304

Original Poster
Rep: Reputation: 21
Quote:
Originally Posted by paulsm4
Posting a few lines of your "/usr/local/bin/clamstats.pl", say from lines 105 - 126, and from lines 49 - 55, might be a good alternative ;-)
You're right, I should have thought of that, here are lines 105 - 126:

$date = "$dow $month $day $time $year";
$startdate = $date if (!defined $startdate);
($hour, $min, $sec) = split(":", $time);

$date =~ s/\d+:\d+:\d+\s//;
$date =~ s/^\w+\s//;
$date =~ s/\s\d+$//;

$stats{date}{$date}++;
$stats{hour}{$hour}++;
$stats{month}{$month}++;
$stats{year}{$year}++;
$stats{virus}{$virus}++;
$stats{count}++;
$stats{type}{$ext}++;

$hourmax = $stats{hour}->{$hour} if ($stats{hour}->{$hour} > $hourmax);
$datemax = $stats{date}->{$date} if ($stats{date}->{$date} > $datemax);
$monthmax = $stats{month}->{$month} if ($stats{month}->{$month} > $monthmax);
$yearmax = $stats{year}->{$year} if ($stats{year}->{$year} > $yearmax);
}

Lines 49 - 55:

return(sprintf "%-2.2d%-2.2d", $months{$month}, $day);
}

sub build_key_mon {
return(sprintf "%-2.2d", $months{$_});
}

and line 317

$TXT .= sprintf("%2d: %6s %s\n", $hr, $stats{hour}->{$hr}, "." x int($hourraw/$hourscale)) if $text;

Thanks for any help

Chris
 
Old 05-30-2006, 07:52 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
quote:
Use of uninitialized value in substitution (s///) at /usr/local/bin/clamstats.pl line 105.

There's no substitution in your example code; I think you need to go back at least one line.
If the lines are co-dependent, prob means you are substituting an uninit value and then trying to use it in the first line you've shown us ie effectively a string cooncat. Notice how you get the same complaint 4 times for line 106, which has 4 string subst/concats in it.
 
Old 05-30-2006, 08:16 PM   #5
Toadman
Member
 
Registered: Aug 2002
Location: Copperas Cove, Texas
Distribution: Ubuntu 20.04 LTS
Posts: 304

Original Poster
Rep: Reputation: 21
Here are lines 96 - 126, possibly this will help:

if (/^\w{3}\s\w{3}\s{1,2}\d{1,2}\s(\d+:){2}\d{2}\s\d{4}\s->\sstream:\s[\w\.\d-]+\sFOUND$/) {
$dow = $1;
$month = $2;
$day = $3;
$time = $4;
$year = $5;
my $id = $6;
my $ext = $7;
my $virus = $8;
$day =~ s/^(\d)$/0$1/;
$date = "$dow $month $day $time $year";
$startdate = $date if (!defined $startdate);
($hour, $min, $sec) = split(":", $time);

$date =~ s/\d+:\d+:\d+\s//;
$date =~ s/^\w+\s//;
$date =~ s/\s\d+$//;

$stats{date}{$date}++;
$stats{hour}{$hour}++;
$stats{month}{$month}++;
$stats{year}{$year}++;
$stats{virus}{$virus}++;
$stats{count}++;
$stats{type}{$ext}++;

$hourmax = $stats{hour}->{$hour} if ($stats{hour}->{$hour} > $hourmax);
$datemax = $stats{date}->{$date} if ($stats{date}->{$date} > $datemax);
$monthmax = $stats{month}->{$month} if ($stats{month}->{$month} > $monthmax);
$yearmax = $stats{year}->{$year} if ($stats{year}->{$year} > $yearmax);
}

Here is the output of running clamstats.pl > cstatsoutput.txt:

ClamAV Statistics
cpollock

--------------------------------------------------------
clamd last started Sat May 20 16:07:28 2006
--------------------------------------------------------
Statistics since
Last Database Update Tue May 30 16:11:24 2006
--------------------------------------------------------
Total viruses detected 92
Total Database Signatures 57,032
--------------------------------------------------------
5 FreshClam errors, last on Thu May 25 14:36:34 2006: Mirrors are not fully synchronized. Please try again later.

1 Virus Types Detected
------------------------------------------
92 100.00%


1 File Extensions Used
--------------------------
92 100.00%


By Date ( . = 1 viruses )
--------------------------
06: : 2 ..
44: : 2 ..
57: : 1 .
15: : 3 ...
21: : 2 ..
14: : 1 .
04: : 4 ....
09: : 1 .
28: : 1 .
22: : 4 ....
10: : 1 .
55: : 4 ....
36: : 1 .
40: : 4 ....
35: : 1 .
37: : 3 ...
27: : 4 ....
05: : 2 ..
24: : 2 ..
12: : 1 .
11: : 1 .
07: : 1 .
31: : 1 .
32: : 1 .
51: : 1 .
20: : 2 ..
54: : 1 .
58: : 1 .
13: : 2 ..
52: : 3 ...
33: : 2 ..
03: : 2 ..
17: : 2 ..
39: : 3 ...
42: : 1 .
50: : 1 .
00: : 2 ..
08: : 1 .
59: : 2 ..
23: : 2 ..
43: : 1 .
02: : 2 ..
19: : 2 ..
56: : 1 .
46: : 1 .
45: : 3 ...
48: : 4 ....
25: : 2 ..


By Hour ( . = 1 viruses )
--------------------------
0: 92 ............................................................................................


By Month ( . = 3 viruses )
-------------------------
: 92 ..............................


By Year ( . = 4 viruses )
--------------------------
: 92 .......................

It partially looks correct, however, the date fields are all wrong. If run from the command line, the errors in my first post are shown, if ran outputting to a txt file they are not. Again, I know absolutely nothing about perl scripts.
 
Old 05-30-2006, 11:45 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
To capture all the output, treat it like a shell script ie capture stdout & stderr like this
yourscript >script.log 2>&1
Basically, the if() statement there is trying to parse a date string of some sort, but it's doing it wrong, hence the rest of the errors.
Are you sure you can't post the script as a script.txt attachment?
 
Old 05-31-2006, 05:57 AM   #7
Toadman
Member
 
Registered: Aug 2002
Location: Copperas Cove, Texas
Distribution: Ubuntu 20.04 LTS
Posts: 304

Original Poster
Rep: Reputation: 21
I see nothing to click that would allow me to upload the script, however I've posted it here:

http://www.easy-sharing.com/473251/clamstats.pl.html

Thanks for any help

Last edited by Toadman; 05-31-2006 at 05:37 PM.
 
Old 05-31-2006, 06:50 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Anybody able to get that script contents? All I get is the link, which pts to itself.
 
Old 05-31-2006, 07:00 PM   #9
Toadman
Member
 
Registered: Aug 2002
Location: Copperas Cove, Texas
Distribution: Ubuntu 20.04 LTS
Posts: 304

Original Poster
Rep: Reputation: 21
Quote:
Originally Posted by chrism01
Anybody able to get that script contents? All I get is the link, which pts to itself.
About 1/4th down the page, under the add for ringtones you'll see this:

http://w05.easy-sharing.com/473251/D...K/clamstats.pl
File size: 12Kb. Downloaded: 0 times

I clicked on it and it worked fine. The link is underlined and in brown text.
 
Old 05-31-2006, 09:40 PM   #10
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Consider e-mailing the clamstat author directly...

Hi -

I looked at your "clamstat.pl" script, and I don't see anything obviously wrong.

HOWEVER ...

I also see that the purpose of the script is to monitor Clam Antivirus logs. My script won't even start, because I don't have Clam installed, so the script isn't finding a Clam logs directory:
Quote:
Couldn't read freshclam logfile /var/log/clamav/freshclam.log
It looks like your problem is that clamstats is finding the logs ... but they aren't in the format the script is expecting. Hence the "Use of uninitialized value" error. Not surprising, since the script was written in 2004 - and Clam A/V has undoubtedly changed their logfile format since then.

SUGGESTION:
Why not contact the original author of Clamstat.pl directly? His blog (and an e-mail link) are here:
http://weblog.infoworld.com/venezia/
 
Old 05-31-2006, 09:51 PM   #11
Toadman
Member
 
Registered: Aug 2002
Location: Copperas Cove, Texas
Distribution: Ubuntu 20.04 LTS
Posts: 304

Original Poster
Rep: Reputation: 21
I did back on 22 May when I couldn't get it to run right. His reply was:

I haven't updated that code in forever, so it's entirely possible
> that this is a parsing error caused by a new log format or something
> similar. If/when I have time I'll update the code. Alternatively, it
> should be relatively simple to modify it to your needs...
>
> -Paul

I know next to nothing about scripts, I've made several small bash scripts to do simple things but thats the extent of my expertise.
 
Old 06-01-2006, 06:12 AM   #12
Toadman
Member
 
Registered: Aug 2002
Location: Copperas Cove, Texas
Distribution: Ubuntu 20.04 LTS
Posts: 304

Original Poster
Rep: Reputation: 21
Would posting a few lines of a clamd log here help?
 
Old 06-01-2006, 05:23 PM   #13
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

I definitely sympathize with you ... but no way can I volunteer to debug somebody else's 400 line Perl script.

Feel free to post a few lines (or even e-mail me directly). If I can help, I'd be happy to.

Otherwise - maybe you could make Mr. Venezia feel guilty enough to update his script (which is still posted on his current site).

Sorry I can't be of more help .. PSM
 
Old 06-01-2006, 06:59 PM   #14
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
That link hates me; when I left click I get the same web page again or right click i get the link text.
 
Old 06-01-2006, 07:38 PM   #15
Toadman
Member
 
Registered: Aug 2002
Location: Copperas Cove, Texas
Distribution: Ubuntu 20.04 LTS
Posts: 304

Original Poster
Rep: Reputation: 21
Hmm, it works ok for me, did you click on the link underneath the ad for 100% Real Tones?

Last edited by Toadman; 06-01-2006 at 07:42 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl Script Program (need) : SpamAssassin-ClamAV-Procmail-Howto cyberjames Slackware 8 01-27-2005 11:53 AM
Apache Stats Shell Script Pho Linux - General 1 12-18-2004 09:41 AM
Run email script from clamav Pete M Programming 0 07-25-2004 04:38 PM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 10:22 AM
Including methods from a perl script into another perl script gene_gEnie Programming 3 01-31-2002 05:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration