Sponsored Content
Top Forums Shell Programming and Scripting purge logs, keep the 30 lasts Post 302448582 by jblecrou on Thursday 26th of August 2010 11:14:38 AM
Old 08-26-2010
purge logs, keep the 30 lasts

Hi,

I have to make a script to purge logs in a directory (this script will run automatically every day) and this script has to keep just the 30 last files.
So I want it to count all the files in the directory, find the 30 most recents and delete the others.

I just started shell scripting and I'm not very good ^^
I tried this :
Code:
#!/bin/sh
FIND=/opt/csw/bin/gfind
DIR=<path to the directory where logs are>
DIR2=<path where the script is>
CREATE_FILE=`ls -ltr $DIR|cut -c54- > $DIR2/lstFile`;
NB_LINE=`cat $DIR2/lstFile|wc -l`;
deb=`expr $NB_LINE - 30`
FileToDelete=`head -n $deb lstFic> lstFileDel`;
DEL_FILE=`cat lstFileDel`
echo $DEL_FILE
$FIND $DIR -type f -name '$DEL_FILE' -exec rm -f {} \;


but the find rm doesn't work, my variable is good the echo displays the files to delete, but the rm does't work...

so if anyone has an idea?or a better solution (I gues there must be a lot^^)


thanks for the help Smilie

Last edited by Franklin52; 08-26-2010 at 01:38 PM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

purge xterm

Being new I had my focus in the wrong place and typed in xterm instead of <If you can't guess, good>. Can I purge xterm so that this word no longer appears using up or down arrows? (1 Reply)
Discussion started by: noobie_doo
1 Replies

2. Shell Programming and Scripting

script for purge

Hi , I want to purge 7 days older data from a list of data sorted on date in a log file... Can anyone provide me with the shell script for the same.. Thanks, Jaz (1 Reply)
Discussion started by: JP003
1 Replies

3. Shell Programming and Scripting

Grep yesterday logs from weblogic logs

Hi, I am trying to write a script which would go search and get the info from the logs based on yesterday timestamp and write yesterday logs in new file. The log file format is as follows: """"""""""""""""""""""""""... (3 Replies)
Discussion started by: harish.parker
3 Replies

4. Shell Programming and Scripting

Remove lasts characters from a string

Hi all, Consider i have a directory /tmp/test and inside this directory i have the following files: 1.svf.tmp 2.svf.tmp 3.svf.tmp How can i remove the last four characters of every file in irder for the directory to be as: 1.svf 2.svf 3.svf I use the following command but id doesn't... (6 Replies)
Discussion started by: chriss_58
6 Replies

5. Shell Programming and Scripting

ftp script : list 4 lasts files

Hi, At work we have backups on a ftp. I want to view 4 last files saved (their names, dates, and weight). how can i achieve this goal using simplest way ? Thank's. (3 Replies)
Discussion started by: simon974
3 Replies

6. Shell Programming and Scripting

script to grep only the lasts errors

Hi, sorry if there already a thread about this, I did a little bit of digging but haven't found exactly what I want. I have a java application on a glassfish server who crash from time to time :D I need a script to allert me if there's a error like "java heappspace" or "out of memory" in the... (5 Replies)
Discussion started by: jblecrou
5 Replies

7. Emergency UNIX and Linux Support

Purge in oracle9i

From morning we are facing some issues in tablespaces in oracle9i. Tried deleting some huge records... but even thought it is still giving tablespcases in full. Then i tried and googling ... found we need to purge recyclebin of oracle.. but thats not woking in oracle9i... can any one... (1 Reply)
Discussion started by: greenworld123
1 Replies

8. Shell Programming and Scripting

Menu for Purge

I have these commands that help me find and delete files over certain days. How can I build a menu to list the files, and then hit y for yes to delete or no? find /logs/212/abinitio/prod/mfs/partitions/part0/mfs_12way_001/mfs_12way/sncrpt/main/ -name "*dat" -mtime +1 -exec ls -ltr {} \; find... (3 Replies)
Discussion started by: xgringo
3 Replies

9. UNIX for Dummies Questions & Answers

Apt-get install --purge

Hello, i would like to know what is the use of that command apt-get install --purgeI understand the use of --purge while using with remove parameter, but i don't get it when it's about installing. Enlight me please ! Thx ---------- Post updated 09-03-16 at 11:35 AM ---------- Previous... (0 Replies)
Discussion started by: Purgator
0 Replies

10. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies
POLYORB-CONFIG(1)					       PolyORB documentation						 POLYORB-CONFIG(1)

NAME
polyorb-config - script to get information about the installed version of PolyORB. SYNOPSIS
polyorb-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version|-v] [--config] [--libs] [--cflags] [--idls] [--help] DESCRIPTION
polyorb-config is a tool that is used to determine the compiler and linker flags that should be used to compile and link programs that use PolyORB. OPTIONS
polyorb-config accepts the following options: --prefix[=DIR] Output the directory in which PolyORB architecture-independent files are installed, or set this directory to DIR. --exec-prefix[=DIR] Output the directory in which PolyORB architecture-dependent files are installed, or set this directory to DIR. --version|-v Print the currently installed version of PolyORB on the standard output. --config Print the configuration of the currently installed version of PolyORB on the standard output. --libs Print the linker flags that are necessary to link a PolyORB program. --cflags Print the compiler flags that are necessary to compile a PolyORB program. --idls Print the flags to set up path to CORBA's IDL for idlac. --with-appli-perso=P,P,P Restrict output to only those flags relevant to the listed applicative personalities. --with-proto-perso=P,P,P Restrict output to only those flags relevant to the listed protocol personalities. --with-corba-services=S,S,S Restrict output to only those flags relevant to the listed services. --help Print help message. AUTHORS
The PolyORB team, polyorb-devel@lists.adacore.com. SEE ALSO
The PolyORB WWW page, http://libre.adacore.com/polyorb/ PolyORB team April 26, 2007 POLYORB-CONFIG(1)
All times are GMT -4. The time now is 04:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy