CPUG: The Check Point User Group

Resources for the Check Point Community, by the Check Point Community.


** Announcing the #CPUGchallenge **

I'm very happy to announce that CPUG will be hosting "The CPUG Challenge" during CPX this year.
It promises to be a fun and interesting event that will test (and maybe even expand) your knowledge of Check Point.
Whether or not you plan to attend CPX, we have something for you. Please check out this post or the CPUGchallenge.com web site for more information. -E

 

Results 1 to 2 of 2

Thread: Rotate log

  1. #1
    Join Date
    2016-09-13
    Location
    Japan
    Posts
    53
    Rep Power
    1

    Default Rotate log

    Hi guys

    Is there a way to use /* /pfrm2.0/bin/rotateLog.sh */ to rotate custom files ?
    My purpose is to rotate logs sent to the sd card.




    Is this possible?

    Tried with /* # /bin/bash /pfrm2.0/bin/rotateLog.sh /var/log/log/THELOG.elg 1000 4 */
    but
    the logs are not rotated.

    Thank you.



    >>> rotateLog.sh

    #!/bin/bash

    # This script rotates a log file to a number of files.
    # When the log file is full, it is renamed, e.g. myLogFile -> myLogFile.1. at which point myLogFile.1 is renamed to myLogFile.2, etc..
    # If the max number of file has been reached, then the oldest file gets deleted.

    # Note: Run this script using a pipe
    # eg: myScript | rotateLog.sh myLogFile 1000 4 (creates up to 4 log files of 1000 byte each)
    # If you want to log stderr as well: myScript 2>&1 | rotateLog.sh myLogFile 1000 4
    # If you want to log only stderr without stdout then do the following 3 commands:
    # exec 3>&1
    # myScript 2>&1 >&3 3>&- | rotateLog.sh myLogFile 1000 4
    # exec 3>&-

    FILENAME=$1 #log file name. rotated files will append a ".1", ".2",... to the name e.g. myLogFile, myLogFile.1, ...
    MAXSIZE=$2 # Max size of the log file in bytes before it rotates the file
    MAXFILES=$3 # Max number of rotated log files. if this number already exists and the log file needs to be rotated, then the oldest file gets deleted

    usage() {
    >&2 echo "Usage: $0 {log_filename} {log_max_size} {max_log_files}" #echos to stderr
    exit 1
    }

    #validations to input
    if [ $# -ne 3 ]; then
    usage
    fi
    if [[ ! ( $2 =~ ^[0-9]+$ && $3 =~ ^[0-9]+$ ) ]]; then
    # MAXSIZE and MAXFILES must be numbers
    usage
    fi

    MAXINDEX=$(( MAXFILES - 1 )) #e.g if 3 files, then the files will be called: myLogFile, myLogFile.1 and myLogFile.2, So MAXINDEX==2
    ROTATING_FLAG_FILE=/fwtmp/rotate${FILENAME//\//_}

    MV=/bin/mv
    RM=/bin/rm
    ECHO=/bin/echo

    while read DATA; do
    if [ -f $FILENAME ]; then
    CURRENT_FILE_SIZE=$(wc -c < "$FILENAME")
    DATA_LEN=${#DATA}
    TOTAL_LEN=$(($CURRENT_FILE_SIZE + $DATA_LEN))
    if [[ ($TOTAL_LEN -gt $MAXSIZE) && ( ! -f $ROTATING_FLAG_FILE ) ]]; then
    $ECHO "1" > $ROTATING_FLAG_FILE
    #rotate the log file
    # First find the number of the last log file
    for (( i=$MAXINDEX; i>0; i-- )); do
    if [ -f $FILENAME.$i ]; then
    LAST_LOG_NUM=$i
    break
    fi
    done
    if [ -z $LAST_LOG_NUM ]; then
    # The file has never been rotated
    $MV $FILENAME $FILENAME".1"
    else
    if [ "$LAST_LOG_NUM" -eq "$MAXINDEX" ]; then
    #we have reach the max number of files. delete the oldest
    $RM $FILENAME.$LAST_LOG_NUM
    ((LAST_LOG_NUM--))
    fi
    for (( i=$LAST_LOG_NUM;i>0;i-- )); do
    # rename files xxx.2 to xxx.3, xxx.1 to xxx.2, etc...
    $MV $FILENAME.$i $FILENAME.$(( $i + 1))
    done
    $MV $FILENAME $FILENAME".1"
    fi
    $RM $ROTATING_FLAG_FILE
    fi
    fi
    $ECHO $DATA >> $FILENAME

  2. #2
    Join Date
    2006-03-08
    Location
    Lausanne
    Posts
    840
    Rep Power
    12

    Default Re: Rotate log

    What's the problem with built-in rotation?
    -------------

    Valeri Loukine
    CCMA, CCSM, CCSI
    http://checkpoint-master-architect.blogspot.com/

Similar Threads

  1. How To Rotate Smartview Tracker Logs on A Weekly Basis
    By harishg9 in forum SmartView Tracker
    Replies: 3
    Last Post: 2012-01-05, 03:51
  2. How do I Rotate the Audit Logs in FireWall-1 NG?
    By Barry J. Stiefel in forum SmartView Tracker
    Replies: 5
    Last Post: 2006-05-30, 00:35
  3. fw logswitch does Not rotate all Logs
    By Barry J. Stiefel in forum SmartView Tracker
    Replies: 0
    Last Post: 2005-08-13, 13:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •