Unix System Administration

ID #1009

How to execute a script during boot up on FreeBSD?

Having FreeBSD to execute a script during boot up is not complicated at all. There are several reasons to want to run a custom script when you start FreeBSD, such as mounting samba shares with spaces in their names (which are not compatible with the fstab file). To begin with, you need to have a shell script ready. If you don't yet, let's create it in the /usr/local/etc/rc.d/ directory as root:

$ su -
# cd /usr/local/etc/rc.d/
# vi myscript.sh

Now, put some code into your shell script:

#!/bin/sh
# This shell script is a test and will paste a "test.txt" file on my desktop
echo 'Test' > ~charles/Desktop/test.txt
chown charles:charles ~charles/Desktop/test.txt

Now, let's make this shell script executable:

# chmod +x myscript.sh

The only thing we have to do now is tell FreeBSD to execute this shell script at bootup:

# vi /etc/rc.conf

Add the following line of code to the rc.conf file:

myscript_enable="YES"

Save. Restart FreeBSD. You should see a test.txt file on your desktop :)

Tags: -

Related entries:

Last update: 2008-09-01 05:53
Author: Charles A. Landemaine
Revision: 1.1

Digg it! Print this record Send to a friend Show this as PDF file
Propose a translation for Propose a translation for
Please rate this entry:

Average rating: 4.18 out of 5 (11 Votes )

completely useless 1 2 3 4 5 most valuable

You cannot comment on this entry