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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem rotating a file!!

Status
Not open for further replies.

roman78

Technical User
Jun 28, 2004
7
MX
A few days ago I posted a thread to know how to write a script to rotate a log file, and I really appreciate the advises that rharsh and PaulTEG gave me, it help me a lot.
Unfortunately I still have problems to write this script, let me tell you that the script would let me to rotate a file, I mean I have 5 files:

message, message1, message2, message3 and message4

The purpouse of this script is to check for the existance of messages.3 and, if it exists, move its contenst to messages.4. Then is should check for messages.2 and move its contents to messages.3 and so on, until messages is moved to messages.1.

What I understood is writing in the following code :

#! /usr/bin/perl

$mess = "messages";
$mess1 = "messages.1";
$mess2 = "messages.2";
$mess3 = "messages.3";
$mess4 = "messages.4";

if (-e $mess3)
{rename($mess3, $mess4);}
elsif (-e $mess2)
{rename($mess2, $mess3);}
elsif (-e $mess1)
{rename($mess1, $mess2);}
elsif (-e $mess)
{rename($mess, $mess1);}

print $mess1;

To make sure this script worked I write inside messages.3 ;"what's wrong??", and supposedly after running the script I would have this statement inside mess.1, but it didn't happen so I don't know how to solve this problem.
I'm a perl newbie,

Can anybody help me??

thanks in advance
 
What kind of errors are you getting when you try to run your script? Also, if I remember your original post correctly, you were running this script from your cron? Have you tried including the path to the files?

Code:
my $path = '/some/dir/';
my $mess = "${path}messages";
my $mess1 = "${path}messages.1";
And so on.
 
you write:

if msg5 .....
elsif msg4 ....
...and so on

if msg5 is FOUND no other statement is executed
Q: does the presence of msg5 EXCLUDE msg4 ?
A: NO NO NO
rewrite you code (possibily in perl, or better)
something like, very abstract:

for(max = ?; max >0; --max){
if not-exists(file.max-1) continue;
rename(file.max-1, file.max);
}

Q: DO YOU NEED THIS AT ALL ???
A: NO NO NO
in your starup script;
rm /path/message ## cool
ln -s /path/message.XXX /path/message ##cooler
program >/path/message

XXX can be
a) the weekday number # will be overwrited next week
b) the mounthday num # will be overwrited next month
c) the yearday num # called julian, will be .. next year
see manpages 'date'





don't forget, RTFMP :) guggach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top