Advertisement
Guest User

rotate logs | CRUX

a guest
Nov 30th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.77 KB | None | 0 0
  1. root@netkicker:~# cat /etc/cron/monthly/syslog
  2. #!/bin/sh
  3. #
  4. # /etc/cron/weekly/syslog: rotate log files
  5. #
  6.  
  7. /root/sbin/logrotate auth cron debug kernel mail messages net all
  8.  
  9. # End of file
  10.  
  11. root@netkicker:~# cat ~/sbin/logrotate
  12. #!/bin/sh
  13. #
  14. # logrotate: rotate and compress logfile(s)
  15. #
  16.  
  17. export PATH='/bin:/usr/bin'
  18.  
  19. ldir="/var/log"
  20.  
  21. [ $# -lt 1 ] && \
  22. { echo "usage : `basename $0` <file> [<file> ..]" ; exit 1 ; }
  23.  
  24. for f in $* ; do
  25.     # skip if does not exists or empty
  26.     [ -s $ldir/$f ] || continue
  27.     # keep up to 9
  28.     for i in {8..0} ; do
  29.         [ -f $ldir/old/$f.$i.xz ] && \
  30.         mv -f $ldir/old/$f.$i.xz $ldir/old/$f.$((1+i)).xz
  31.     done
  32.     cp -p $ldir/$f $ldir/old/$f.$i && \
  33.     : > $ldir/$f && xz $ldir/old/$f.$i
  34. done
  35.  
  36. # End of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement