Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

move () stumped

Status
Not open for further replies.

grazinggoat

Programmer
Joined
Mar 12, 2008
Messages
41
Location
US
Happy New Year Guru's! :)

I am having a problem with my script renaming/moving files
the move() and also tried rename() doesn't seem to like the .gz
after i compress the file. when i run the script it gives

A.log20120118053018PSTgz

Any thoughts?


Here is what I am doing:


$A_Log = "$A.log";
$B_Log = "$B.log";

my @files = ( $A_Log, $B_Log );

foreach $logFile (sort(@files)) {
chomp($logFile);
print "$logFile\n"; #debug
if ( -e $logFile ) {
$fsize = (stat($logFile))[7];
if ( $fsize >= 5000000 ) {
system("/bin/gzip -9 $logFile");
print "$logFile\n"; #debug
move( $logFile.gz, $logFile.(strftime '%Y%m%d%H%M%S%Z', localtime time).gz ) or die "Could not move gzip'd file $logFile: $!\n";
print "info: $logFile compressed and moved...\n";

}
else {
print "info: $logFile does not need to be moved...\n";
}
}
else {
print "info: $logFile does not exist\n";
}

} # End foreach Loop


 
Hi

grazinggoat said:
doesn't seem to like the .gz
A concatenation operator and a bareword ? I agree with Perl, neither I like that.
Code:
[COLOR=darkgoldenrod]move[/color][teal]([/teal] [navy]$logFile[/navy][teal].[/teal][green][i]'.gz'[/i][/green][teal],[/teal] [navy]$logFile[/navy][teal].([/teal]strftime [green][i]'%Y%m%d%H%M%S%Z'[/i][/green][teal],[/teal] localtime time[teal]).[/teal][green][i]'.gz'[/i][/green] [teal])[/teal]
As I have no idea from where that strftime comes, I did not tested the code.

Feherke.
 
Ahhh.. Noted Feherke on the concatenation and bareword! I'm coming along thought!
Thank you, Sir! :)

My turn to share with you....
As for strtime.. It's from calling POSIX module.

strtime - Convert date and time information to string. Returns the string.
 
Hi

grazinggoat said:
As for strtime.. It's from calling POSIX module.
Ah, right. perldoc.perl.org's search engine returns "No matches found" in all categories when searching for "strftime". Thanks, next time I will use Google instead.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top