For the love of God, put
system maintenance tasks into the
system‑wide
/etc/crontab (or a
/etc/cron.d/… file).
Why don’t you say so? Focus your “solution”
on the problem – unnecessarily
huge log files – by
checking their size. If you insist on the
sledgehammer method, use
truncate(1):
Bash:
#!/bin/sh
# name: cleaner
# description: nuke logs exploding in size
# author: kerogaz <mailbox@somewhere.anywhere>
# Find files allocating 1 GiB or more worth of 512 B-blocks
# and truncate them to a size of 0 B.
exec find /var/log -size +1G -exec truncate -s 0 '{}' '+'
This script don't works
Jul 27 08:00:00 cel /usr/sbin/cron[29228]: (root) CMD (/root/clean.sh)
/var/log
total 5616
-rw------- 1 root wheel 2393 Jul 27 08:58 auth.log
-rw------- 1 root wheel 18929 Jul 27 09:05 cron
-rw------- 1 root wheel 92000 Jul 27 03:01 dmesg.today
-rw------- 1 root wheel 0 Jul 26 22:00 dmesg.yesterday
-rw------- 1 root wheel 175 Jul 27 03:01 ipfw.today
-rw------- 1 root wheel 0 Jul 26 22:00 ipfw.yesterday
-rw-r----- 1 root wheel 797 Jul 27 03:40 maillog
-rw-r----- 1 root wheel 102 Jul 27 00:00 maillog.0.bz2
-rw-r--r-- 1 root wheel 0 Jul 26 22:00 messages
-rw------- 1 root wheel 146 Jul 27 03:01 mount.today
-rw------- 1 root wheel 0 Jul 26 22:00 mount.yesterday
-rw------- 1 root wheel 2996 Jul 27 03:01 setuid.today
-rw------- 1 root wheel 0 Jul 26 22:00 setuid.yesterday
-rw-r--r-- 1 unbound unbound 5552299 Jul 27 09:07 unbound.log
-rw-r--r-- 1 root wheel 197 Jul 27 08:58 utx.lastlogin
-rw-r--r-- 1 root wheel 826 Jul 27 08:58 utx.log
clean.sh:
#!/bin/sh
# name: cleaner
# description: nuke logs exploding in size
# author: kerogaz <
mailbox@somewhere.anywhere>
# Find files allocating 1 GiB or more worth of 512 B-blocks
# and truncate them to a size of 0 B.
exec find /var/log -size +1G -exec truncate -s 0 '{}' '+'