Log ext


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Log ext
# 1  
Old 07-24-2013
Log ext

I have a script that does log rotation, at 10000k, it will print out the logs as follows:

name.date.0.log(1gb)
name.date.1.log(1gb)
name.date.2.log(200mb) << current log being written to

at midnight it reverts back to : name.date.0.log(size)

I want it to be able to go past date.9.log into double digits like name.date.10.log
Code:
CURRENT_APSLOG=$($FIND $LOGDIR -type f -name "aps_20*.0_0.log" | sort -r | head -1)
  CURRENT_APSLOGDATE=$(basename "$(echo $CURRENT_APSLOG | sed -e 's/.0_0.log$//')")
  #echo "CURRENT_APSLOG: $CURRENT_APSLOG"
  #echo "CURRENT_APSLOGDATE: $CURRENT_APSLOGDATE"
  for l in $($FIND $LOGDIR -type f -name "aps_20*.*.log" -a ! -name "${CURRENT_APSLOGDATE}.*.log")
  do
    #echo "log: $log"
    # for backward compat with HP find has no -mmin so use mmin.pl
    mmin.pl $l +60
    if [ $? -eq 0 ]
    then
      BASENM=$(basename "$l")
      NEWNM=${ARCDIR}/${BASENM}
      # move it to the archive directory
      mv $l $NEWNM
    fi
  done
done

I am sure that I just need to copy this snippet over and add a new variable to the current log since it will not match any others...but I am at a loss of exactly how this should be looked at. Any assitance is appreciated. Thanks

Last edited by bigbenn; 07-24-2013 at 06:27 PM..
# 2  
Old 07-24-2013
This doesn't look like the thing that rotates the logfiles, exactly... It looks for files older than 60 minutes and moves them.

I take it the difficulty is because it sorts alphabetically, rather than by numbers? 1 10 2 3 4 5 6 7 8 9, vs 1 2 3 4 5 6 7 8 9 10?

I think sorting by date with ls would work better than using find and sorting the names.

Code:
# basename should not be needed, because of cd
# the cd will not persist outside the $( )
CURRENT_APSLOG=$( cd $LOGDIR ; ls -t aps_20*.0_0.log | head -n 1)

# 3  
Old 07-25-2013
Well there is a lot more to this script than that snippet...as well as it calls upon a logfunction tha thas subroutines for ziplog, rototate log and other stuff. But I see what you are saying, that's why I am confused on it
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. IP Networking

One router, 2 machines, to OS, 2 different ext. IP's?

I even don't dare to ask for a hint, but as I am looking for clues may someone can help me, though reading me bsd handbook. It is about one machine running as media play studio with a debian distro and one machine running bsd 10.2 connected to one router. By booting first the debian machine it... (4 Replies)
Discussion started by: 1in10
4 Replies

2. Shell Programming and Scripting

ext File

I have a log file that I want to extract the field name and the field value and write them to a text file for importation it a database table for reporting purposes. How can I extract the desired data from this file . Example: dbt_dbid=4 dbt_dbid is the field name 4 is the field value... (4 Replies)
Discussion started by: JolietJake
4 Replies

3. Shell Programming and Scripting

Recursively *.ext files using find

HI, Getting the syntax error " find: missing conjunction" for the below code D1_DIR=/x/y/z D1_NAME=file_name FILE_DIR=pset for file in `find ${D1_DIR}/${D1_NAME} -name "*\.${FILE_DIR}" /dev/null {} \;` do echo $file done #Trying to find all the files with *.pset... (5 Replies)
Discussion started by: cvsanthosh
5 Replies

4. Shell Programming and Scripting

du -s *.ext (total)

How would I get a total of a wildcard of files from the 'du' command? du -s *.pdf Result: 736 11mens_bracket.pdf 64 2011_NIT_Bracket_3_13_11.pdf 80 Doing more with Less part1.pdf 1064 Doing more with Less part2.pdf 28 Parkview_1309_Garage.pdf 3964 statsheet-bracket-2011.pdf Expected... (7 Replies)
Discussion started by: AlphaLexman
7 Replies

5. HP-UX

Limitation on *.ext

Is there a size limit when passing an argument using wildcards? I.E. when I pass an argument in the form (like) "ftp_auto *.txt" - is there a limitation on the size of UNIX expanding "*.txt" ? (1 Reply)
Discussion started by: vslewis
1 Replies

6. UNIX for Dummies Questions & Answers

Help with a ext. modem on SCO 5.0.5

I am fully capable of reading a book to get the answers or looking to the web, but no one has the answer to this one. I had a Zoom 56K V34 Plus external modem (2836A) attached to my Unix box for about ten years without a flaw. This weekend I couldn't access the box remotely through the modem and... (0 Replies)
Discussion started by: scivic
0 Replies

7. UNIX for Dummies Questions & Answers

How to delete files with certain ext?

Hi All, How can I work on following request? Delete all the html files older than 29th November from the path - /dding/ting/tong/unixyang/output (4 Replies)
Discussion started by: tonyvirk
4 Replies
Login or Register to Ask a Question