Go Back   DaemonForums > FreeBSD > FreeBSD General

FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below.

Thread Tools Display Modes
  #1   (View Single Post)  
Old 18th February 2019
hanzer's Avatar
hanzer hanzer is offline
Real Name: Adam Jensen
just passing through
Join Date: Oct 2013
Location: EST USA
Posts: 314
Default How to execute a command at system startup

My FreeBSD system needs to execute a couple simple commands sometime during or shortly after the boot process. After a bit of searching, it seems many people have this need and there doesn't seem to be a canonical solution. There is much written about managing services (daemons) but learning the details of rc.d scripting in order to execute a command (# camcontrol apm 0:0:0 -l 250) seems like [s]a dirty[/s] an absurd hack. The rc man page says:
The rc.local script contains
commands which are pertinent only to a specific site. 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. In this case, it
should source /etc/rc.conf and contain additional custom startup code for
your system. The best way to handle rc.local, however, is to separate it
out into rc.d/ style scripts and place them under /usr/local/etc/rc.d/.
This is the only information I could find about /etc/rc.local (was this vague, sentimental man page blurb written by a child?). If anyone here is familiar with rc.local syntax and its use within the FreeBSD rc system, if you could post a simple, best practices example of a working script, that would be very helpful!
Reply With Quote
  #2   (View Single Post)  
Old 19th February 2019
J65nko J65nko is offline
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,065

You can create a crontab entry with the "@reboot" time/period specifier. From crontab(5) :

Instead of the first five fields, a line may start with `@' symbol fol-
 lowed either by one of eight special strings or by a numeric value.  The
 recognized special	strings are:

	   string	   meaning
	   ------	   -------
	   @reboot	   Run once, at	startup	of cron.
You can create a simple shell script that runs/executes whatever you want to run at reboot,

Please keep in mind that your script runs with a very limited subset of environment settings like PATH.
From the shell execute which env and enter the results in your first iteration of the script, The resulting output of the script will be mailed locally. Inspect that mail to see the environment settings.
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #3   (View Single Post)  
Old 21st February 2019
hanzer's Avatar
hanzer hanzer is offline
Real Name: Adam Jensen
just passing through
Join Date: Oct 2013
Location: EST USA
Posts: 314

Thanks for suggesting the workaround. I did this:

$ sudo crontab -u root -e
@reboot /sbin/camcontrol apm 0:0:0 -l 250
@reboot /sbin/camcontrol apm 1:0:0 -l 250
The machine is too busy to test it...
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
AWK passing the argument to system command Oko Programming 6 6th July 2011 08:03 PM
Scripted sysinstall fails with "Command 'system' failed" PeterSteele FreeBSD Installation and Upgrading 0 13th November 2008 11:31 PM
execute commands from xinitrc rex FreeBSD General 3 22nd October 2008 10:24 PM
Execute a command during login rex FreeBSD General 4 12th September 2008 08:09 PM
ruby execute commands remotely Dr_Death_UAE Programming 0 18th August 2008 11:23 AM

All times are GMT. The time now is 09:17 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick