# dos2unix /etc/config/rc.local
Another scenario would be to call another custom script from the /etc/config/rc.local file, making sure
that your custom script will run whenever the system is booted.
15.1.2 Running custom scripts when alerts are triggered
Whenever an alert gets triggered, specific scripts get called. These scripts all reside in /etc/scripts/.
Below is a list of the default scripts that get run for each applicable alert:
- For a connection alert (when a user connects or disconnects from a port or network host):
/etc/scripts/portmanager-user-alert (for port connections) or /etc/scripts/sdt-user-alert (for host
connections)
- For a signal alert (when a signal on a port changes state): /etc/scripts/portmanager-signal-alert
- For a pattern match alert (when a specific regular expression is found in the serial ports character
stream): /etc/scripts/portmanager-pattern-alert
- For a UPS status alert (when the UPS power status changes between on line, on battery, and low
battery): /etc/scripts/ups-status-alert
- For a environmental, power and alarm sensor alerts (temperature, humidity, power load, and
battery charge alerts): /etc/scripts/environmental-alert
- For an interface failover alert: /etc/scripts/interface-failover-alert
All of these scripts do a check to see whether you have created a custom script to run instead. The code
that does this check is shown below (an extract from the file /etc/scripts/portmanager-pattern-alert):
# If there's a user-configured script, run it instead
scripts[0]="/etc/config/scripts/pattern-alert.${ALERT_PORTNAME}"
scripts[1]="/etc/config/scripts/portmanager-pattern-alert"
for (( i=0 ; i < ${#scripts[@]} ; i++ )); do
if [ -f "${scripts[$i]}" ]; then
exec /bin/sh "${scripts[$i]}"
fi
done
This code shows that there are two alternative scripts that can be run instead of the default one. This
code first checks whether a file "/etc/config/scripts/pattern-alert.${ALERT_PORTNAME}" exists. The
variable ${ALERT_PORTNAME} must be replaced with "port01" or "port13" or whichever port the alert
should run for. If this file cannot be found, the script checks whether the file
"/etc/config/scripts/portmanager-pattern-alert" exists. If either of these files exists, the script calls the
exec command on the first file that it finds and runs that custom file/script instead.
As an example, you can copy the /etc/scripts/portmanager-pattern-alert script file to
/etc/config/scripts/portmanager-pattern-alert:
# cd /
# mkdir /etc/config/scripts (if the directory does not already exist)
# cp /etc/scripts/portmanager-pattern-alert /etc/config/scripts/portmanager-pattern-alert
The next step will be to edit the new script file. First, open the file /etc/config/scripts/portmanager-
pattern-alert using vi (or any other editor), and remove the lines that check for a custom script (the code
from above). This will prevent the new custom script from repeatedly calling itself. After these lines have
been removed, edit the file, or add any additional scripting to the file.
_____________________________________________________________________
724-746-5500 | blackbox.com Page 237