Como digo en el asunto tengo un problema moviendo un fichero. He estado haciendo pruebas pero no logro saber en qué me falla. Creo que se debe a algo relacionado con los valores de las variables... en fin, os digo de que se trata:
- Tengo un programa en Perl que tiene varias funciones a las que va llamando durante la ejecución del programa.
- El programa al empezar creó un fichero que sirve de log. El nombre del log se guarda en la variable global $LOG_FILE_NAME y su actual path en otra variable global $DUMP_PATH. La siguiente función me crea el fichero log:
Using perl Syntax Highlighting
sub StartLogFile {
#Starting log name with the present date.
my @current_date = localtime();
my ($sec,$min,$hour,$day,$month,$year) = ($current_date[0], $current_date[1], $current_date[2], $current_date[3], $current_date[4]+1, $current_date[5]+1900);
$LOG_FILE_NAME = "Dump_log_".$day."_".$month."_".$year."_".$hour."_".$min.".txt ";
if( -e "$DUMP_PATH/$LOG_FILE_NAME") {
open (LOG_FILE, '>>'."$DUMP_PATH/$LOG_FILE_NAME");
}
else {
open (LOG_FILE, '>'."$DUMP_PATH/$LOG_FILE_NAME");
print LOG_FILE "<$LOG_FILE_NAME> LOG - <day-month-year> - <hour-min-sec>\n"
}
print LOG_FILE "\n";
print LOG_FILE "=============================================\n";
print LOG_FILE "DUMP LOG $day-$month-$year - $hour:$min:$sec\n";
print LOG_FILE "=============================================\n";
}
#Starting log name with the present date.
my @current_date = localtime();
my ($sec,$min,$hour,$day,$month,$year) = ($current_date[0], $current_date[1], $current_date[2], $current_date[3], $current_date[4]+1, $current_date[5]+1900);
$LOG_FILE_NAME = "Dump_log_".$day."_".$month."_".$year."_".$hour."_".$min.".txt ";
if( -e "$DUMP_PATH/$LOG_FILE_NAME") {
open (LOG_FILE, '>>'."$DUMP_PATH/$LOG_FILE_NAME");
}
else {
open (LOG_FILE, '>'."$DUMP_PATH/$LOG_FILE_NAME");
print LOG_FILE "<$LOG_FILE_NAME> LOG - <day-month-year> - <hour-min-sec>\n"
}
print LOG_FILE "\n";
print LOG_FILE "=============================================\n";
print LOG_FILE "DUMP LOG $day-$month-$year - $hour:$min:$sec\n";
print LOG_FILE "=============================================\n";
}
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4
- Durante la ejecución del programa, otra función escribe en el fichero log. Hasta aquí no hay problema. El fichero se crea y va escribiendo. Al final quiero cambiar el fichero de sitio y lo hago con esta función:
Using perl Syntax Highlighting
sub ExitScript{
chomp(my $exit_code = $_[0]);
if($exit_code == 0){
WriteTextInLog("Script finished without errors\n");
}
else{
WriteTextInLog("Script finished with errors\n");
}
close LOG_FILE;
foreach (@DB_NAME){
my $current_log_path = "$DUMP_PATH/$LOG_FILE_NAME";
my $new_log_path = "$DUMP_PATH/$_/$LOG_FILE_NAME";
if(-e $current_log_path){
print "Voy a mover de: [$current_log_path] a: [$DUMP_PATH/$_]\n";
rename($current_log_path,$new_log_path);
if(!-e "$DUMP_PATH/$_/$LOG_FILE_NAME") {
print "ExitScript::Moving log file to dump from [$DUMP_PATH/$LOG_FILE_NAME] to [$DUMP_PATH/$_]-- [ERROR]\n";
print "Error moving log file. The current log file is still in [$DUMP_PATH/$LOG_FILE_NAME]\n";
}
}
else{
print "ExitScript::Moving log file to dump from [$DUMP_PATH/$LOG_FILE_NAME] to [$DUMP_PATH/$_]-- [ERROR]\n";
print "Log file in [$DUMP_PATH/$LOG_FILE_NAME] not found!\n";
}
}
}
chomp(my $exit_code = $_[0]);
if($exit_code == 0){
WriteTextInLog("Script finished without errors\n");
}
else{
WriteTextInLog("Script finished with errors\n");
}
close LOG_FILE;
foreach (@DB_NAME){
my $current_log_path = "$DUMP_PATH/$LOG_FILE_NAME";
my $new_log_path = "$DUMP_PATH/$_/$LOG_FILE_NAME";
if(-e $current_log_path){
print "Voy a mover de: [$current_log_path] a: [$DUMP_PATH/$_]\n";
rename($current_log_path,$new_log_path);
if(!-e "$DUMP_PATH/$_/$LOG_FILE_NAME") {
print "ExitScript::Moving log file to dump from [$DUMP_PATH/$LOG_FILE_NAME] to [$DUMP_PATH/$_]-- [ERROR]\n";
print "Error moving log file. The current log file is still in [$DUMP_PATH/$LOG_FILE_NAME]\n";
}
}
else{
print "ExitScript::Moving log file to dump from [$DUMP_PATH/$LOG_FILE_NAME] to [$DUMP_PATH/$_]-- [ERROR]\n";
print "Log file in [$DUMP_PATH/$LOG_FILE_NAME] not found!\n";
}
}
}
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
- El problema es que me dice que ¡no existe el fichero log que he creado! He puesto un sleep() antes de que compruebe si existe o no y puedo acceder a él sin problemas, pero cuando lo comprueba Perl me dice que hay errores.
¿Alguien me puede ayudar por favor?
¡Gracias por adelantado!