some people managed to get on the moon, i managed to limit log files to x lines. monthly.

both processes were complicated.

one would expect tail to do the job.

but tail -n 100 filename.log > filename.log

would write „“ (nothing) into filename.log if filename.log has less than 100 lines.

the trick is to write to a new file, than move new to old file.

# test run, it will not output anything
test -x /usr/sbin/cron-apt && /usr/sbin/cron-apt

# how to truncate shrink log files

mkdir /scripts

echo "#! /bin/sh
mv $FILENAME'_new' $FILENAME;" > /scripts/

chmod 755 /scripts/

# shrink log to 100 lines
/scripts/ /usr/sbin/cron-apt 100;

# check what it did
cat /var/log/cron-apt/log