Craig Sharp wrote: > It sounds simple but here is the situation. > > I have DB2 creating log files. Each file name is consecutive. > > Eg: > > S0000628.LOG > S0000629.LOG > S0000630.LOG > S0000631.LOG > S0000632.LOG > S0000633.LOG > S0000634.LOG > S0000635.LOG > S0000636.LOG > S0000637.LOG > S0000638.LOG > S0000639.LOG > S0000640.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 S0000640.LOG, I am to remove all logs prior to S0000629.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 Luebkert Mailto:[EMAIL PROTECTED] (_/ / ) // // DBE Collectibles Mailto:[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