OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • Archive »
  • 18.1 Legacy Series »
  • How to add custom commands at boot via rc or crontab
« previous next »
  • Print
Pages: [1]

Author Topic: How to add custom commands at boot via rc or crontab  (Read 4644 times)

sandro87

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
How to add custom commands at boot via rc or crontab
« on: September 11, 2018, 12:30:50 pm »
Hello,
I'm trying to add custom commands at boot (this is not a service or daemon!) to run at every boot, it just needs to cd to a directory and rename a file. nothing else.
I tried to follow the freeBSD documentation which says to put the .sh file containing the command in /usr/local/etc/rc.d/ which is completey ignored it seems, even if I enable rc_debug it logs nothing.
If I change the crontab using @reboot it's deleted by opnsense at every boot.

What should I do?
Logged

franco

  • Administrator
  • Hero Member
  • *****
  • Posts: 13624
  • Karma: 1173
    • View Profile
Re: How to add custom commands at boot via rc or crontab
« Reply #1 on: September 12, 2018, 03:06:14 pm »
Take a look at these docs:

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


Cheers,
Franco
Logged

sandro87

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
Re: How to add custom commands at boot via rc or crontab
« Reply #2 on: September 12, 2018, 03:40:53 pm »
Quote from: franco on September 12, 2018, 03:06:14 pm
Take a look at these docs:

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


Cheers,
Franco

Hello,
thanks! The first solution looks like the one I'm looking for.
Just two things:
1) the docs show a directory system like "/usr/local/etc/rc.syshook.d/early/50-yourscript"
On my build I don't have any subdirectory, just files like 20-freebsd.start . Is it because I'm using and old version (18.1)?
2) I tried both version anyway and nothing seems to work, maybe I'm missing something. Is there a way to debug this?

My script is a simple test like this

Code: [Select]
#!/bin/bash

touch /home/hotspotuser/testfile

I don't see why it shouldn't work
Logged

sandro87

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
Re: How to add custom commands at boot via rc or crontab
« Reply #3 on: September 12, 2018, 04:23:15 pm »
Nevermind, the 50-myscript.start worked!  :D
Logged

franco

  • Administrator
  • Hero Member
  • *****
  • Posts: 13624
  • Karma: 1173
    • View Profile
Re: How to add custom commands at boot via rc or crontab
« Reply #4 on: September 12, 2018, 04:25:55 pm »
Hi sandro87,

You are using a version < 18.7 I think. The docs reflect the reality in 18.7, but scripts are automatically migrated on update so it'll keep working.


Cheers,
Franco
Logged

  • Print
Pages: [1]
« previous next »
  • OPNsense Forum »
  • Archive »
  • 18.1 Legacy Series »
  • How to add custom commands at boot via rc or crontab
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2023 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2