Nk_csf_load_threshold
Description
The script expects the user to provide a numerical load average
as an argument. It then saves the value as a variable named “load”. It backs up the existing configuration file for CSF before modifying it using the sed
command to replace the current load value with the provided value. It then prints out the new value set as confirmation, restarts CSF, and lets the user know that it restarted.
Example
Just run the command and provide whatever value you want the load threshold to be.
[root@cloudvpsserver ~]# nk_csf_load_threshold 4 PT_LOAD_LEVEL set to 4 csf restarted.
Code
nk_csf_load_threshold() { # nk_csf_load_threshold expects to have a load number provide. Print error and exit if blank if [ "$1" = "" ]; then echo "You must provide a numerical load average" return 0 fi # Otherwise the value the user provide is saved as variable load. load="$1" # First back up the existing config file. cp -a /etc/csf/csf.conf /etc/csf/.csf.conf."$(date +%F)" # Then modifty using sed to replace the current load value with the variable we created earlier. sed -i 's/PT_LOAD_LEVEL = "[0-9]\+"/PT_LOAD_LEVEL = "'"$load"'"/' /etc/csf/csf.conf # Print out the new value set as confirmation. grep -E "^PT_LOAD_LEVEL" /etc/csf/csf.conf # Then restart csf, redirect stdout to /dev/null to keep it from flooding the terminal. csf -r > /dev/null # Let the user know we restarted csf. echo csf restarted. }