Help - Search - Member List - Calendar
Full Version: Logger output behavior not wanted
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Pablo Wolter
Hi,

I have some troubles to figuring out by myself a way to add the output
of a script that I run by system function in perl into a logger. The
code I have is:

----------------------------------------------------------------------------

#!/usr/bin/perl

use Fcntl qw( O_RDONLY O_WRONLY O_CREAT );
use IO::File;

$timeStamp=`date '+%m%d%Y:%H%M'`;
chomp($timeStamp);
$hostName=`/bin/uname -n`;
chomp($hostName);
$makeBackup="/home/pwolter/cstools/bin/makeBackup";
$errorCode=0;
$errorLog="/home/pwolter/pablo/tools/bin/geoDbBackup";
chomp($errorLog);

$errorLogFile="$errorLog"."$timeStamp.log"; # This is working perfect !!!
chomp($errorLogFile);

sysopen (LOG,$errorLogFile,O_WRONLY|O_CREAT, 0600)
or die "Cannot write to file $errorLogFile $!n";

$| = 1;

print LOG "------ $hostName Database backupn";
print LOG "------ Database backup started at: $timeStampnn";

system("$makeBackup >> $errorLogFile"); # this i want on the logger

sleep 180; # I try this without success

if ( $? != 0 ) {
$errorCode=1;
} else {
$errorCode=0;
}

if ( $errorCode == 1 ) {
print LOG "n------ Backup process end with errors!n";
} else {
print LOG "n------ Backup process end successfully!n";
$endTimeStamp=`date '+%m%d%Y:%H%M'`;
chomp($endTimeStamp);
print LOG "n------ Backup process end at: $endTimeStampn";
}
---------------------------------------------------------------------------------------


This is the content of my logger:


----------------------------------------------------------------------------

------ Database backup
------ Database backup started at: 06272005:1449


------ Backup process end successfully!

------ Backup process end at: 06272005:1453
tabase backup file is:
/home/pwolter/cstools/dbBackup.2005.06.27.19.49.tar.gz

If this backup file is to be archived somewhere else
create a text file /home/pwolter/cstools/dbBackup.2005.06.27.19.49
In the text file record the location of actual backup file.

------------------------------------------------------------------------------------------------------------------------

And this is what I like this file to be:


------------------------------------------------------------------
------ Database backup
------ Database backup started at: 06272005:1449


tabase backup file is:
/home/pwolter/cstools/dbBackup.2005.06.27.19.49.tar.gz

If this backup file is to be archived somewhere else
create a text file /home/pwolter/cstools/dbBackup.2005.06.27.19.49
In the text file record the location of actual backup file.

------ Backup process end successfully!
------ Backup process end at: 06272005:1453

-----------------------------------------------------------------------------

Any help will be good because I'm a litle lost on this

Thanks in advance

Pablo.

Dave Gray
On 6/27/05, Pablo Wolter <[Email Removed]> wrote:
QUOTE
Hi,

I have some troubles to figuring out by myself a way to add the output
of a script that I run by system function in perl into a logger. The
code I have is:
[snip]
print LOG "------ $hostName Database backupn";
print LOG "------ Database backup started at: $timeStampnn";

system("$makeBackup >> $errorLogFile"); # this i want on the logger

You can do:

print LOG qx"$makeBackup";


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.