Load a script on boot.

Hi guys!
Since I can't do it in any way... Please, someone tell me how to load, at boot, with FreeBSD 14.2-RC1, a very simple script that contains:
#!/bin/sh
/usr/sbin/ntpdate ntp.ien.it

Thanks for the answer.
 
You should probably stop using ntpdate(8), it will be deprecated in a future version.
Code:
     Note: The functionality of this program is now available in the ntpd(8)
     program.  See the -q command line option in the ntpd(8) page.  After a
     suitable period of mourning, the ntpdate utility is to be retired from
     this distribution.

Use nptd_enable="YES" and maybe add ntpd_sync_on_start="YES". Configure the time server in /etc/ntp.conf.

That said, put the command in /etc/rc.local. It still works, see rc(8)
Code:
     The rc utility is the command script which controls the automatic boot
     process after being called by init(8).  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/.
     The rc.conf file contains the global system configuration information
     referenced by the startup scripts, while rc.conf.local contains the local
     system configuration.  See rc.conf(5) for more information.
 
You should probably stop using ntpdate(8), it will be deprecated in a future version.
Code:
     Note: The functionality of this program is now available in the ntpd(8)
     program.  See the -q command line option in the ntpd(8) page.  After a
     suitable period of mourning, the ntpdate utility is to be retired from
     this distribution.

That said, put the command in /etc/rc.local.
This is my first time using FreeBSD, can you please write me the code? I tried but I can't... This is what I put in /etc/rc.local but it doesn't work:
#!/bin/sh -e
/home/freebsd/datetime.sh
exit 0

Thanks for the reply.
 
I tried but I can't... This is what I put in /etc/rc.local but it doesn't work
Just as SirDice mentioned: IF you just want a good date & time at boot, just add to /etc/rc.conf
Code:
ntpd_enable="YES"
ntpd_sync_on_start="YES" #sync time at startup in a big leap; after that gentle clock synchronization
Then reboot.
👉 You don't need to program anything.


However, if you want to write a rc script that will be used at boot, read and try understanding first how it works:
  1. Chapter 14. Configuration, Services, Logging and Power Management
  2. Practical rc.d scripting in BSD
  3. rc(8) and rc.subr(8)
Again, you do not need to program a rc script to set the time at boot!
 
Adding things to /etc/rc.local is generally working for this.

You lack error messages, so it is better to do this:
Code:
/usr/sbin/ntpdate ntp.ien.it 2>&1 | tee /var/log/mystuff.log

Apart from using the ntpdate facility already built in :)
 
Adding things to /etc/rc.local is generally working for this.

You lack error messages, so it is better to do this:
Code:
/usr/sbin/ntpdate ntp.ien.it 2>&1 | tee /var/log/mystuff.log

Apart from using the ntpdate facility already built in :)
Thanks cracauer@ for the advice, but nothing to do!
Is it possible that it is so complicated to make a script [or a command] run at FreeBSD boot? I mean a script in general, not necessarily the one I posted...
 
you can start ntpd at boot and add the sync server in /usr/etc/ntp.conf:
Bash:
...

#
# To configure a specific server, such as an organization-wide local
# server, add lines similar to the following.  One or more specific
# servers can be configured in addition to, or instead of, any server
# pools specified above.  When both are configured, ntpd first adds all
# the specific servers, then adds servers from the pool until the tos
# minclock/maxclock targets are met.
#
#server time.my-internal.org iburst
server ntp.ien.it iburst

...

I have a local time server, I'm not shure if it works for external internet servers.

FreeBSD by default installas ntpd (bsdinstall) and put the following in rc.conf:
Bash:
#-----------
# NTP daemon
ntpd_enable="YES"
ntpd_sync_on_start="YES"
so you only have to add the server as above
 
Put a line into crontab(5) for root user starting with @reboot.
By far, the more sensible solution (given the stated problem) is to fix ntpd.conf (as it SHOULD be fixed to correspond to the actual $SITE) and let the existing rc mechanisms handle it as a "normal" system would.

While you could create a special rc.local -- or a crontab entry -- those are things that you'd have to remember having done.

By contrast, you look at rc.conf(5) and see that ntpd is enabled... then, go lookig at the configuration file for ntpd. No need to leave breadcrumbs reminding yourself about some "out-of-band" solution that you cooked up!
 
Back
Top