#!/bin/bash
#-------------------------------------------------------------------------------
# charon_rotatelog for Charon-PAR
#-------------------------------------------------------------------------------
# Copyright (C) 2013-2023 STROMASYS.
# All rights reserved.
#-------------------------------------------------------------------------------
# $1 = log file, full path, to rename (usually from the service definition file)
#-------------------------------------------------------------------------------
#set -x
VERSION=2.0

if test -z "$1"
then
  echo "Please specify file name, full path, as parameter 1."
else
  if test -f "$1"
  then
    while test 1
    do
      LOGFRENEXT="upto"$(date +%F-%H%M%S)
      if test -e ${FDIR}/${FNAM}.${LOGFRENEXT}.log
      then
        sleep 1
      else
        mv -f $1 $1.${LOGFRENEXT}
        if test $? = 0
        then
          echo "Moved '$1' to '$1.${LOGFRENEXT}'."
        else
          echo "Failed to move '$1' to '$1.${LOGFRENEXT}'. Continuing..."
        fi
        break
      fi
    done
  else
    echo "File '$1' not found. Normal situation on 1st run."
  fi
fi

exit

