I need to run a very simple 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?

migrated from serverfault.com Sep 11 at 7:48

This question came from our site for system and network administrators.

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 as 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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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