OPNsense Forum

English Forums => General Discussion => Topic started by: Patrick M. Hausen on July 24, 2020, 08:31:56 AM

Title: Recommended place for user created shell scripts?
Post by: Patrick M. Hausen on July 24, 2020, 08:31:56 AM
Hi all,

if I want to set up some custom cron jobs, is there an official recommendation where to put them?
My main concern is that I want them to survive a firmware upgrade, of course.

Thanks,
Patrick
Title: Re: Recommended place for user created shell scripts?
Post by: franco on July 24, 2020, 09:03:07 AM
Hi Patrick,

Add your scripts somewhere and register actions for them like so:

https://docs.opnsense.org/development/backend/configd.html

When you use a "description" these actions (your scripts) will show up in the System: Settings: Cron GUI for use.


Cheers,
Franco
Title: Re: Recommended place for user created shell scripts?
Post by: Patrick M. Hausen on July 24, 2020, 09:49:30 AM
Hi Franco,

I don't need UI access. It's only cron jobs. I just wanted to be sure the next upgrade won't wipe e.g. /usr/local/sbin/myscript.sh or similar.

I guess placing them into /home somewhere will do.

Thanks,
Patrick
Title: Re: Recommended place for user created shell scripts?
Post by: Patrick M. Hausen on July 24, 2020, 10:34:22 AM
Ah ... now I get it. I assumed that System --> Settings --> Cron would let you specify arbitrary commands.
Seems like it doesn't.

Thanks again
Patrick
Title: Re: Recommended place for user created shell scripts?
Post by: franco on July 24, 2020, 01:03:21 PM
You can't manipulate cron without a defined backend action. Config files will revert defaults otherwise. That's why this is a bit more work initially, but can be automated as a plugin package if mass deployment is relevant. :)

We generally avoid the ability to tie custom scripts to working code directly, especially through config.xml.

Separate files and scripts are never touched by the system unless the file name appears in the packages at some point in time. Just make sure to create a separate directory that is unlikely to ever appear (i.e. /usr/local/mycoolscripts)


Cheers,
Franco