OPNsense Forum

Archive => 22.7 Legacy Series => Topic started by: PJ79 on November 21, 2022, 07:28:35 am

Title: Crontab is not keeping job related to user entries
Post by: PJ79 on November 21, 2022, 07:28:35 am
Hi Guys
First of all welcome all of You!
Maybe someone faced the same issue as me.
There are logs /var/log/filter which I need to clean up every week due to limited space assigned to Opnsense
I'm running two routers ( Master and Slave)
OPNsense 22.7.4-amd64
FreeBSD 13.1-RELEASE-p2
OpenSSL 1.1.1q 5 Jul 2022

I have created a simple bash script which is cleaning logs from /var/log/filter. This script is working in 100% as manual execution seems to result in what I want.

The issue is with crontrab where I have added an entry to start the script ( crontab -e)
0 1 * * * /root/bin/filter_bkp.sh
Then of course entry is saved and looks ok for some time. 
Unfortunately, after around a week, this entry is removed ( no user action) and of course, logs are not removed.

Any thoughts
Br, Pawel

Title: Re: Crontab is not keeping job related to user entries
Post by: franco on November 21, 2022, 08:19:16 am
You should add a permanent backend job as per https://docs.opnsense.org/development/backend/configd.html

Also add a "description" to be able to select it from cron GUI and you can do this without it disappearing later on.


Cheers,
Franco
Title: Re: Crontab is not keeping job related to user entries
Post by: Patrick M. Hausen on November 21, 2022, 08:36:37 am
@franco Why doesn't the UI permit the creation of arbitrary cron jobs? I always wondered. I mean, just enter the 5 frequency fields, the user, and the command line - piece of cake. So it can't be a complexity issue.
Title: Re: Crontab is not keeping job related to user entries
Post by: chemlud on November 21, 2022, 08:42:23 am
...hmm... why isn't there any CLI in the GUI (aynmore)? ;-)
Title: Re: Crontab is not keeping job related to user entries
Post by: franco on November 21, 2022, 09:05:19 am
The GUI is not suitable for registering backend scripts as we do not want to store custom scripting in the config.xml. This is what the plugin system is for.


Cheers,
Franco
Title: Re: Crontab is not keeping job related to user entries
Post by: Patrick M. Hausen on November 21, 2022, 09:43:27 am
I do not want to register a backend script. Just run a single arbitrary command. I question the entire need for "backend scripts". This could work just like tuneables. There I can set whatever I deem necessary instead of choosing from a predefined list. See the cron job interface of TrueNAS for comparison.
Title: Re: Crontab is not keeping job related to user entries
Post by: franco on November 21, 2022, 10:01:30 am
This is a privilege escalation issue so we will not add arbitrary commands (or scripts).


Cheers,
Franco
Title: Re: Crontab is not keeping job related to user entries
Post by: Patrick M. Hausen on November 21, 2022, 10:30:32 am
Understood. We do have individual admin users, but all of them with full access.  :)
Title: Re: Crontab is not keeping job related to user entries
Post by: PJ79 on November 23, 2022, 08:48:26 am
Seems like franco comment helped me :)
Thank you, guys.
Title: Re: Crontab is not keeping job related to user entries
Post by: abulafia on November 23, 2022, 10:11:41 pm
You should add a permanent backend job as per https://docs.opnsense.org/development/backend/configd.html
Great - thank you for the pointer (and apologies for not RTFM).

Here is a very simple action for ZFS scrub and ZFS trim:

Code: [Select]
[trim]
command:zpool trim
parameters: %s
type:script_output
message: Run ZFS trim on specified pool
description: zpool trim [zpool]

[scrub]
command:zpool scrub
parameters: %s
type:script_output
message: Run ZFS scrub on specified pool
description: zpool scrub [zpool]

Is it possible to permanently save a script like zrep, zrepl, znapzend or syncoid/sanoid to the OPNsense system to enable periodic snapshots (and automatic pruning thereof)?

Or would it be possible to use and persistently configure the FreeBSD periodic.conf system?
Title: Re: Crontab is not keeping job related to user entries
Post by: franco on November 24, 2022, 11:49:49 am
There was a thread recently and periodic.conf (or better periodic.conf.local) can be used at will, but needs to be edited from the shell.

You can also use your backend cron jobs this way...

# configctl zfs trim zpool

(given the actions file is actions_zfs.conf)


Cheers,
Franco
Title: Re: Crontab is not keeping job related to user entries
Post by: franco on November 24, 2022, 11:50:22 am
PS: https://forum.opnsense.org/index.php?topic=30993.0
Title: Re: Crontab is not keeping job related to user entries
Post by: abulafia on November 24, 2022, 12:04:36 pm
PS: https://forum.opnsense.org/index.php?topic=30993.0
Thanks!