Solved Cron don't work

You won't get confused in Arch, Debian and Rocky ...
Debian uses systemd, so the logs are not kept in files in /var/log but in databases. Setting up the moral equivalent of log rotate in systemd is easy and more flexible; I just enable SystemMaxUse in the config file, and keep a fixed amount of disk space for the journals.
 
Debian uses systemd, so the logs are not kept in files in /var/log but in databases. Setting up the moral equivalent of log rotate in systemd is easy and more flexible; I just enable SystemMaxUse in the config file, and keep a fixed amount of disk space for the journals.
Arch has systemd but I use journalctl for show logs
 
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 '{}' '+'
 
Seems to work fine. It took all the scripts that were over 1G in size and truncated them: there were none!

Did you actually read the comment and the find command in the script Kai posted?
 
I put limit 100K -don't works

find: -size: +100K: illegal trailing character

Only +1M works

And I want to reset all files regardless of size
 
From the man page for find:

Code:
 -size n[ckMGTP]
             True if the file's size, rounded up, in 512-byte blocks is n.  If
             n is followed by a c, then the primary is true if the file's size
             is n bytes (characters).  Similarly if n is followed by a scale
             indicator then the file's size is compared to n scaled as:

             k       kilobytes (1024 bytes)
             M       megabytes (1024 kilobytes)
             G       gigabytes (1024 megabytes)
             T       terabytes (1024 gigabytes)
             P       petabytes (1024 terabytes)
 
Back
Top