[Perl-unix-users] Removing a set of consecutive file names from a directory

2003-12-01 Thread Craig Sharp
It sounds simple but here is the situation.

I have DB2 creating log files.  Each file name is consecutive.

Eg:

S628.LOG
S629.LOG
S630.LOG
S631.LOG
S632.LOG
S633.LOG
S634.LOG
S635.LOG
S636.LOG
S637.LOG
S638.LOG
S639.LOG
S640.LOG

The DBA wants me to remove all logs from the logging directory except
the last 10 logs from the active log.  For example.  If the active log
is S640.LOG, I am to remove all logs prior to S629.LOG.

Can anyone give me an idea on how to do this.  I do not want to do this
by date.  Only by name.

Thanks,

Craig A. Sharp
Unix Systems Administrator
DNS Administrator
Security Administrator
Roush Industries
Office: 734-466-6286
Cell: 734-231-6769
Fax: 734-466-6939
[EMAIL PROTECTED]

I have not lost my mind, it's backed up on tape somewhere!


CONFIDENTIALITY NOTE 
This electronic transmission, including all attachments, is directed in
confidence solely to the person(s) to which it is addressed, or an
authorized recipient, and may not otherwise be distributed, copied or
disclosed. The contents of the transmission may also be subject to
intellectual property rights and all such rights are expressly claimed
and are not waived. If you have received this transmission in error,
please notify the sender immediately by return electronic transmission
and then immediately delete this transmission, including all
attachments, without copying, distributing or disclosing same.

___
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: [Perl-unix-users] Removing a set of consecutive file names from a directory

2003-12-01 Thread $Bill Luebkert
Craig Sharp wrote:

> It sounds simple but here is the situation.
> 
> I have DB2 creating log files.  Each file name is consecutive.
> 
> Eg:
> 
> S628.LOG
> S629.LOG
> S630.LOG
> S631.LOG
> S632.LOG
> S633.LOG
> S634.LOG
> S635.LOG
> S636.LOG
> S637.LOG
> S638.LOG
> S639.LOG
> S640.LOG
> 
> The DBA wants me to remove all logs from the logging directory except
> the last 10 logs from the active log.  For example.  If the active log
> is S640.LOG, I am to remove all logs prior to S629.LOG.
> 
> Can anyone give me an idea on how to do this.  I do not want to do this
> by date.  Only by name.

I hate globbing, so I would use opendir/readdir and either iterate
over the files checking for /^S\d{7,7}\.log$/ and saving them in an
array.

Then just sort the array and remove the last 10 with splice or
whatever.  Now just unlink the array items either all at once
or in a for loop (which would allow individual error checking).


-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED]
  / ) /--<  o // //  Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff)

___
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: [Perl-unix-users] Removing a set of consecutive file names from a directory

2003-12-01 Thread $Bill Luebkert
Craig Sharp wrote:

> It sounds simple but here is the situation.
> 
> I have DB2 creating log files.  Each file name is consecutive.
> 
> Eg:
> 
> S628.LOG
> S629.LOG
> S630.LOG
> S631.LOG
> S632.LOG
> S633.LOG
> S634.LOG
> S635.LOG
> S636.LOG
> S637.LOG
> S638.LOG
> S639.LOG
> S640.LOG
> 
> The DBA wants me to remove all logs from the logging directory except
> the last 10 logs from the active log.  For example.  If the active log
> is S640.LOG, I am to remove all logs prior to S629.LOG.
> 
> Can anyone give me an idea on how to do this.  I do not want to do this
> by date.  Only by name.

I had globbing, so I would use opendir/readdir and either iterate
over the files checking for /^S\d{7,7}\.log$/ and saving them in an
array.

Then just sort the array and remove the last 10 with splice or
whatever.  Now just unlink the array items either all at once
or in a for loop (which would allow individual error checking).


-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED]
  / ) /--<  o // //  Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff)

___
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: [Perl-unix-users] Removing a set of consecutive file names from a directory

2003-12-01 Thread Matt Schneider
You could do something like this:

# get a list of log files somehow
@logs = `ls *.log`;
# remove the new lines from the end of each element due to
# the way I generated the list
chomp @logs;
# make sure the list is in order
@logs = sort @logs;
# remove all but the last 10 archive log files and the active log file
for ($i=0; $i<$#logs-10; $i++) {
unlink "$logs[$i]";
}

Matthew Schneider
System Administrator / Programmer
SKLD Information Services, LLC
303.820.0863


-Original Message-
From: Craig Sharp [mailto:[EMAIL PROTECTED]
Sent: Monday, December 01, 2003 7:12 AM
To: [EMAIL PROTECTED]
Subject: [Perl-unix-users] Removing a set of consecutive file names from
a directory


It sounds simple but here is the situation.

I have DB2 creating log files.  Each file name is consecutive.

Eg:

S628.LOG
S629.LOG
S630.LOG
S631.LOG
S632.LOG
S633.LOG
S634.LOG
S635.LOG
S636.LOG
S637.LOG
S638.LOG
S639.LOG
S640.LOG

The DBA wants me to remove all logs from the logging directory except
the last 10 logs from the active log.  For example.  If the active log
is S640.LOG, I am to remove all logs prior to S629.LOG.

Can anyone give me an idea on how to do this.  I do not want to do this
by date.  Only by name.

Thanks,

Craig A. Sharp
Unix Systems Administrator
DNS Administrator
Security Administrator
Roush Industries
Office: 734-466-6286
Cell: 734-231-6769
Fax: 734-466-6939
[EMAIL PROTECTED]

I have not lost my mind, it's backed up on tape somewhere!


CONFIDENTIALITY NOTE 
This electronic transmission, including all attachments, is directed in
confidence solely to the person(s) to which it is addressed, or an
authorized recipient, and may not otherwise be distributed, copied or
disclosed. The contents of the transmission may also be subject to
intellectual property rights and all such rights are expressly claimed
and are not waived. If you have received this transmission in error,
please notify the sender immediately by return electronic transmission
and then immediately delete this transmission, including all
attachments, without copying, distributing or disclosing same.

___
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

___
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: [Perl-unix-users] Removing a set of consecutive file names froma directory

2003-12-01 Thread Craig Sharp
Bill,

Can you please give and example?

Thanks,

Craig

>>> "$Bill Luebkert" <[EMAIL PROTECTED]> 12/01/03 09:29AM >>>
Craig Sharp wrote:

> It sounds simple but here is the situation.
> 
> I have DB2 creating log files.  Each file name is consecutive.
> 
> Eg:
> 
> S628.LOG
> S629.LOG
> S630.LOG
> S631.LOG
> S632.LOG
> S633.LOG
> S634.LOG
> S635.LOG
> S636.LOG
> S637.LOG
> S638.LOG
> S639.LOG
> S640.LOG
> 
> The DBA wants me to remove all logs from the logging directory
except
> the last 10 logs from the active log.  For example.  If the active
log
> is S640.LOG, I am to remove all logs prior to S629.LOG.
> 
> Can anyone give me an idea on how to do this.  I do not want to do
this
> by date.  Only by name.

I had globbing, so I would use opendir/readdir and either iterate
over the files checking for /^S\d{7,7}\.log$/ and saving them in an
array.

Then just sort the array and remove the last 10 with splice or
whatever.  Now just unlink the array items either all at once
or in a for loop (which would allow individual error checking).


-- 
  ,-/-  __  _  _ $Bill Luebkert   
Mailto:[EMAIL PROTECTED] 
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED] 
  / ) /--<  o // //  Castle of Medieval Myth & Magic
http://www.todbe.com/ 
-/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers
stuff)

___
Perl-Unix-Users mailing list
[EMAIL PROTECTED] 
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
___
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: [Perl-unix-users] Removing a set of consecutive file names froma directory

2003-12-01 Thread $Bill Luebkert
Craig Sharp wrote:

> Bill,
> 
> Can you please give and example?

Nope - not today.  I'm forcing people to read the man pages today.

perlfunc man page functions:  opendir, readdir, closedir, grep, splice, sort, unlink

perlre/perlretut man pages to learn about regular expressions.

An example of globbing was already posted (I hate globbing and
it's not so portable), but it saves a little code.

I assume you can handle a for loop.

-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED]
  / ) /--<  o // //  Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff)

___
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs