How do I set a script that it will run on start up in FreeBSD?

FreeBSD's cron understands the @reboot time directive, so you can indeed have cron execute your script at startup. Instead of the usual 5 time fields, your crontab entry might look like this:

@reboot /path/to/script

If you want also to run the check when you log in, add a call to the script in the file your shell executes upon login - this could be, depending on your shell, ~/.login, ~/.bash_login, etc.


On FreeBSD 11 for ARMv6 (Raspberry Pi), I couldn't get the crontab @reboot directive to work for the root user, and the "add scripts to the /etc/rc.local file" method has been superseded by a mechanism that automatically runs scripts located in /usr/local/etc/rc.d/.

In other words, to run a script on boot on FreeBSD 11 (or 10?) and likely newer, place an executable shell script with the .sh extension in this folder to have it executed on boot:

/usr/local/etc/rc.d/

You may need to create the rc.d folder if it doesn't exist.

See http://www.defcon1.org/html/rc-local.html for details.


Another solution for startup script would be /etc/rc.local.