S
Simon
Hi guys!
Hope you can help.
Im a newbie to this, but have some sample code that Im trying to understand.
The goal is that I can successfully write a log function that writes
messages to a log file.
Please bare with me as I dont fully understand the below code, which is
where I need your gurus expertise.
Here is the code, which is not working, but Id like to try and find out how
i can get it to work to write messages to a log file.
Any help appreciated.
Thank you.
====================================================================== code
sub Log {
@g = localtime time;
open(LOG,">>$LogFile");
printf LOG "%02d%02d/%02d/%02d %02d:%02d:%02d $_[0]\n",
sprintf("%02d",(substr sprintf("%03d",$g[5]), 0, 1) + 19),(substr
sprintf("%03d",$g[5]), 1, 2),$g[4]+1,$g[3],$g[2],$g[1],$g[0];
printf "%02d%02d/%02d/%02d %02d:%02d:%02d $_[0]\n",
sprintf("%02d",(substr sprintf("%03d",$g[5]), 0, 1) + 19),(substr
sprintf("%03d",$g[5]), 1, 2),$g[4]+1,$g[3],$g[2],$g[1],$g[0];
close(LOG);
}
sub WaitForInstall() {
Log " Waiting for installation to complete";
sleep 10;
$finished = 0;
while (!$finished) {
sleep 5;
$finished = 1; # assume we're finished
open(PS,"$PSCMD|");
while (<PS>) {
if ($_ =~ /$Product Setup/i) {
$finished = 0; # not finished
}
elsif ($_ =~ /$Product/i) {
$finished = 0; # not finished
}
}
close(PS);
}
}
$LogFile = "C:\\logs\\$Product.log";
====================================================================== code
So basically, what Im trying to do is, insert a Log function into particular
parts of the script, and wherever I insert the Log function, to write that
line to Product.log.
The above is only a snippet.
Any help will be great.
I just dont know how to call the Log function, or how to actually write it
to be honest.
The below is my objective.
1) Write a log function (subroutine)
2) Being able to call that log subroutine anywhere in my script, and log
messages from that call to a text file.
Thanku in advance.
Hope you can help.
Im a newbie to this, but have some sample code that Im trying to understand.
The goal is that I can successfully write a log function that writes
messages to a log file.
Please bare with me as I dont fully understand the below code, which is
where I need your gurus expertise.
Here is the code, which is not working, but Id like to try and find out how
i can get it to work to write messages to a log file.
Any help appreciated.
Thank you.
====================================================================== code
sub Log {
@g = localtime time;
open(LOG,">>$LogFile");
printf LOG "%02d%02d/%02d/%02d %02d:%02d:%02d $_[0]\n",
sprintf("%02d",(substr sprintf("%03d",$g[5]), 0, 1) + 19),(substr
sprintf("%03d",$g[5]), 1, 2),$g[4]+1,$g[3],$g[2],$g[1],$g[0];
printf "%02d%02d/%02d/%02d %02d:%02d:%02d $_[0]\n",
sprintf("%02d",(substr sprintf("%03d",$g[5]), 0, 1) + 19),(substr
sprintf("%03d",$g[5]), 1, 2),$g[4]+1,$g[3],$g[2],$g[1],$g[0];
close(LOG);
}
sub WaitForInstall() {
Log " Waiting for installation to complete";
sleep 10;
$finished = 0;
while (!$finished) {
sleep 5;
$finished = 1; # assume we're finished
open(PS,"$PSCMD|");
while (<PS>) {
if ($_ =~ /$Product Setup/i) {
$finished = 0; # not finished
}
elsif ($_ =~ /$Product/i) {
$finished = 0; # not finished
}
}
close(PS);
}
}
$LogFile = "C:\\logs\\$Product.log";
====================================================================== code
So basically, what Im trying to do is, insert a Log function into particular
parts of the script, and wherever I insert the Log function, to write that
line to Product.log.
The above is only a snippet.
Any help will be great.
I just dont know how to call the Log function, or how to actually write it
to be honest.
The below is my objective.
1) Write a log function (subroutine)
2) Being able to call that log subroutine anywhere in my script, and log
messages from that call to a text file.
Thanku in advance.