Need help with: Clearing logs with bash script

Hello! I’m trying to write a simple bash script to make daily backup of logs in openhab and clear them. Unfortunetly, when I’m just clearing the content of openhab.log and events.log, the openhab still remembers old logs and restore old capacity of files. To make it clear: for example, file openhab.log is 15MB size, then I make a backup file, clear content of original file, what make it size to 0MB, but when something happens that is writeing to that file, it size is coming back to 15MB.
Any advice how to clear log files without restarting openhab? I know that you can do it in karaf console with logs:clear (or something similar), but I don’t know how to do this via bash script.

Openhab is running on Raspberry Pi with Raspbian OS.

Delete the file instead of trying to clear it. OH will create a new file on the next write. Have a look at /etc/cron.daily/logrotate for how stuff like this is normally handled.

If deleting the file doesn’t change the behavior and you are on an SD card there is a chance that the card is failing.

@JBr Just a thought… have you considered lowering the logging level down. You can make Openhab log less information

Levels are Debug, Error, Warning, Info etc…

I lowered mine down and a month later, the log files barely 1-2 megabytes in size… and obviously I turn it back up if I need to debug errors. But this could be another way to tackle data sprawl/disk space if thats your concern. FYI… this is what I set mine to (I cant remember what the defaults are, so this may give you the comparison to figure that).

Logger │ Level
───────────────────────────────────────────────────┼──────
ROOT │ WARN
javax.jmdns │ ERROR
javax.mail │ ERROR
org.apache.karaf.jaas.modules.audit │ INFO
org.apache.karaf.kar.internal.KarServiceImpl │ ERROR
org.apache.karaf.shell.ssh.SshUtils │ ERROR
org.apache.karaf.shell.support │ OFF
org.eclipse.lsp4j │ OFF
org.eclipse.smarthome │ INFO
org.jupnp │ ERROR
org.openhab │ INFO
org.openhab.ui.paper │ WARN
org.openhab.ui.paper.internal │ INFO
org.ops4j.pax.url.mvn.internal.AetherBasedResolver │ ERROR
org.ops4j.pax.web.pax-web-runtime │ OFF
smarthome.event │ WARN
smarthome.event.InboxUpdatedEvent │ ERROR
smarthome.event.ItemAddedEvent │ ERROR
smarthome.event.ItemRemovedEvent │ ERROR
smarthome.event.ItemStateEvent │ ERROR
smarthome.event.ThingAddedEvent │ ERROR
smarthome.event.ThingRemovedEvent │ ERROR
smarthome.event.ThingStatusInfoEvent │ ERROR