How to automatically execute commands when pfSense start

PfSense executed at boot custom commands, there are three main methods: shellcmd, earlyshellcmd and Shell scripts.

shellcmd shellcmd management plug-in tag and earlyshellcmd GUI, so no corresponding value manually edit config.xml.

At boot time, the first execution earlyshellcmd command, and then perform shellcmd, and finally execute a shell script when initializing the package.

A, shellcmd way

config.xml options in <shellcmd> will run the specified command at the end of the system boot process.

To shellcmd added to the configuration, you may be used shellcmd plug configuration command, as shown below:

You can also be configured manually edited. Through the " System diagnostics"> "Backup / Restore" XML file system configuration file backup, and then in a text editor (do not use Windows Notepad) to open generated. In </ system> row above, adding a line, as follows:

<shellcmd>mycommand -a -b -c 123</shellcmd>

You can add multiple lines to execute multiple commands. Save the modified file and restore the modified configuration file to the system. The next time the system starts, it will automatically execute the following command:

mycommand -a -b -c 123

Two, earlyshellcmd way

config.xml options in < earlyshellcmd> runs the specified start command at the boot process. You should generally use <shellcmd> instead. And <shellcmd> the same, you want to add <earlyshellcmd> option, use shellcmd plug-in or manually edit the configuration file. Opens with a text editor backup configuration file, and then adding a line, such as above </ system> FIG :

<earlyshellcmd>mycommand -a -b -c 123</earlyshellcmd>

You can add multiple lines to execute multiple commands. Save the modified file and restore the modified configuration file to the system. The next time the system starts, it will automatically execute the following command:

mycommand -a -b -c 123

Three, shell scripts mode

Any shell script can be placed /usr/local/etc/rc.d/ directory. The file name must .sh end, must be marked as executable file (). The directory to each .sh will be executed at the end of the boot shell script. Similar to the following command in a shell interface:

chmod +x myscript.sh

In general, try to use the first two ways, because they remain in the configuration file, if you reinstall pfSense firewall, you only need to restore backup files on it.


Guess you like

Origin blog.51cto.com/fxn2025/2447228