Hi all,
I have the following Perl script which is intended to run a Shell script and generate some logging for the purposes of tracking weather or not the script ran.
I get an error, of course, since I don't know what I'm doing really.
Here is the code:
#!/opt/perl/bin/perl -w
# Using recommended pragmas
use strict;
use warnings;
use File::Basename;
my $Directory = "/directory/script";
my $LogFile = $Directory . "/logs/" . basename($0, ".pl") . ".log"; my $RunFile = $Directory . "/logs/" . basename($0, ".pl") . ".run"; my $RunScript = $Directory . "/directory/script/script.sh";
my $OutfileH; #Output File Handle
print $OutfileH;
# Make sure another instance isn't already running my $pp = Proc::Pidfile->new (pidfile => $RunFile) or die "Unable to create pidfile: $RunFile\n";
open( $OutfileH, '>>', $LogFile);
print $OutfileH &nicetime . ":Running script - " . $RunScript . "\n"; close($OutFileH);
#Run the shell script through perl program system( $RunScript, ">>/directory/script/logs/script.log 2>&1" ) == 0 or print $OutFileH &nicetime "Script FAILED\n" or exit(1); exit(0);
#Functions
##########################################################################
sub nicetime {
my ( $sec, $min, $hour, $mday, $mon, $year, $yday, $isdst ) = localtime(time);
my $timestr = sprintf "%4d-%02d-%02d %02d:%02d:%02d", $year + 1900, $mon + 1, $mday, $hour, $min, $sec;
return $timestr; };
The errors I get are:
String found where operator expected at script.pl line 25, near "&nicetime "Script FAILED\n"" (Missing operator before "Script FAILED\n"?)
Global symbol "$OutFileH" requires explicit package name at scrit.pl line 22.
Global symbol "$OutFileH" requires explicit package name at talend.pl line 25.
syntax error at script.pl line 25, near "&nicetime "Script FAILED\n""
Execution of script.pl aborted due to compilation errors.
