script_stats($runtime, $start);
The script is run from /Perl and the module is located in /Perl/Modules Here the entire (very small) module.
#!/usr/bin/perl use warnings; use strict; use DBD::mysql; package ScriptUpdate; our @ISA = qw(Exporter); our @EXPORT = qw(script_stats); # symbols to be exported by default + (space-separated) our $VERSION = 1.10; sub script_stats { my ($runtime, $rundate) = @_; chomp(my $filename = $0); chomp(my $currentuser=`whoami`); #Holds modified date for file my $mtime = stat($filename)->mtime; my $dbh = DBI->connect("DBI:mysql:database=ts_tool_track:host=xxxx +",'xxxx','xxxx') || die "$DBI::errstr\n"; my $sql = "SELECT ID, Name FROM ScriptDetails WHERE Name='$filenam +e'"; my $sth = $dbh->prepare ( $sql ); $sth->execute(); my @row = $sth->fetchrow_array(); if (exists $row[1] and $row[1] eq $filename) { #If run before \ exists update fields { my $sql = "UPDATE ScriptDetails SET LastModified=from_unix +time($mtime),LastRunTime='$runtime',LastRunDate=from_unixtime($rundat +e),LastRunBy='$currentuser', AvgRunTime = ((AvgRunTime + $runtime) / +2), TotalRuns = TotalRuns+1 WHERE ID='$row[0]' L +IMIT 1"; my $sth = $dbh->prepare ( $sql ); $sth->execute(); } } else { #If first time run, create entry { my $sql = "INSERT INTO ScriptDetails (Name, LastModified, +LastRunTime, LastRunDate, LastRunBy, AvgRunTime, TotalRuns) VALUES('$ +filename',from_unixtime($mtime),'$runtime',from_unixtime($rundate/100 +0),'$currentuser', '$runtime', '1')"; my $sth = $dbh->prepare ( $sql ); $sth->execute(); } } $sth->finish(); $dbh->disconnect(); } 1;
When I try and run it I get the following error.
Undefined subroutine &main::script_stats called at TLEQUERY.pl line 88.
Any hints? First time using packages. Least I got it to find it.
In reply to Help using self-made but very simple Module by kdmurphy001
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |