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

custom logrotate 2

Status
Not open for further replies.

richardko

Programmer
Jun 20, 2006
127
0
0
US
i have a cron job that downloads a file from a remote location.
is it possible to use logrotate to have the files from the last 30 days save at a particular location?
thanks
ro
 
Can you describe your exact requirement in more detail? Perhaps with an example? It may be possible with logrotate, but depending on what you want to do it might be simpler with a one-line cron job.

Annihilannic.
 
thanks for the reply.
Well, every night i have a cron job that downloads a xml file. i parse the xml and enter the data into a database.
For company purposes I want to save the xml files for the last 30 days into a particular folder.


 
At the end of the cron job, just add a couple of commands like this to archive the processed file and then remove any such files modified more than 30 days ago:

[tt]mv processed_file.xml /some/archive/folder
find /some/archive/folder -type f -mtime +30 -exec rm {} \;[/tt]

Annihilannic.
 
Here is a script I put together to rotate some log (or other) files. Feel free to modify to suit your needs

The script:
Code:
#!/bin/ksh
#***************************************************************************
#* Created by: Scott Brewster                                              *
#*       Date: October 2006                                                *
#*   Location: TBD                                                         *
#*                                                                         *
#* Description                                                             *
#* ----------------------------------------------------------------------- *
#* Read the rotatelogs.conf file and rotate that file.  Keep 13 copies     *
#*                                                                         *
#*     Date       Modified By     Reason for modification                  *
#* -----------  ----------------  ---------------------------------------- *
#* 15-Oct-2006  Scott Brewster    Created                                  *
#*                                                                         *
#***************************************************************************
CONFIG=/usr/admin/bin/rotatelogs.conf        #location of configuration file
GZIP=/usr/bin/gzip
#
# Check for config file
#
if [ ! -f $CONFIG ] ; then
   echo "\nError $0: no config file found.\n"
   echo "Create: /usr/admin/bin/rotatelogs.conf\n\n"
   echo "The file format is:\n\n   location, pipe symbol, log file name\n\nIE\t /var/log/|ssh.log\n\n"
   exit
fi
#
# Parse config file and rotate logs
#
for NAME in `cat $CONFIG`
do

  DIR="`echo $NAME | cut -d'|' -f1`"
  LOG="`echo $NAME | cut -d'|' -f2`"

  integer COUNT=12
  while [ $COUNT -ge 1 ]
  do
    if [ -f $DIR$LOG.gz.$COUNT ]
      then
        integer TMP=0
        (( TMP = COUNT + 1 ))
        mv $DIR$LOG.gz.$COUNT $DIR$LOG.gz.$TMP
    fi
    (( COUNT = COUNT - 1 ))
  done
  $GZIP -S .gz.1 -9 $DIR$LOG
  touch $DIR$LOG
done

and here is an example of the rotatelogs.conf file:

Code:
/home/scbrewst/logs/|sdb.log
/home/scbrewst/logs/security/|sbrews.log
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top