3.137.220.120 |    

Navigation

Google Advertisement



file_rotate
  1. # *******************************************************
  2. # This function make a file rotation.
  3. #
  4. # @param $1 - The path to the file (logfile path)
  5. # @param $2 - The rotation interval (default:7)
  6. # @param $3 - Empty the original file (default:0)
  7. # @return void
  8. #
  9. function file_rotate () {
  10.  
  11. local file=$1
  12. local maxlog=${2:-7}
  13. local empty=${3:-0}
  14.  
  15. for j in $(seq $((maxlog-1)) -1 1); do
  16.         mv ${file}"."{$j,$((j+1))} 2>/dev/null
  17. done
  18.  
  19. # Copy the original file to file.1
  20. [ -f "${file}" ] && cp ${file} ${file}.1
  21.  
  22. # Clean the original file
  23. [ ${empty} -eq 1 ] && echo -n >${file}
  24.  
  25. }
Parsed in 0.002 seconds at 375.52 KB/s

Search
 
Full text search by name and content of a snippet.

User online
There are 5 users online.

Tags Cloud

Latest snippets
str2seconds
(Bash::Function)
is_integer
(Bash::Function)
file_rotate
(Bash::Function)
confirm
(Bash::Function)
is_workingtime
(Bash::Function)
last day of last month
(Bash::Snippets)
crypt_apr1_md5
(PHP::Function)
crypt_apr1_md5
(Perl::Function)
transparent
(CSS)
rfc2822Toiso8601
(PHP::Function)