I need to run a command at startup on my machine using FreeBSD:

cd /home/portal
mv portal.sqlite corrupt_portal.sqlite

This is clearly not a daemon or a service, just a one time command at every boot.

I tried to put a .sh file inside /usr/local/etc/rc.d/ with #!/bin/bash and it doesn't do anything, I also tried to simply write touch testfile If I run both versions manually they work with no problem.

What am I missing here?


2 Answers 2


The rc(8) script is responsible for running the automatic boot process, and the example section of the manual gives a simple template for the /etc/rc.d/ directory. Read the rc.subr(8) manual page for further guidance on writing startup scripts.

However, one of the final stages of the automatic boot process is to read a script file called /etc/rc.local (if it exists). This file requires no special formatting or keywords, or the execute bit set.

From the rc(8) manual page:

Typically, the /usr/local/etc/rc.d/ mechanism is used instead of rc.local these days but if you want to use rc.local, it is still supported.


The easiest way is to put that command to the crontab.
Instead of first five fields usually filled by asterisks you can place the special token @reboot

@reboot root:wheel /path/to/the/command [args ...] 

This command will be launched each time the system been rebooted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.