我使用php和bash生成monit配置文件/etc/monit.conf
我在转义双引号和单一忽略匹配模式规则
我正在使用php preg_quote()
函数来转义用户输入文本
我试着用双引号引用字符串并用
\ and \\ => Error: regex parsing error:Trailing backslash
and \\\ => Error: syntax error '\*\?\[\^\]\$\'
## Monitoring log files
Check file file.log with path /file/path
ignore match "\\\+\"\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:\-"
if match "ERROR" then alert
简单引用相同
## Monitoring log files
Check file file.log with path /file/path
ignore match '\\\+\'\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:\-'
if match "ERROR" then alert
在php中
$monit_settings['SUPRESS_KEYWORDS'] = base64_encode($_POST['SUPRESS_KEYWORDS']);
write_shell_config_ini($monit_settings, "../config/monit.ini");
$script = "config-generator-monit.sh";
exec("$script"); // i am using sudo to execute this script
monit.ini
SUPRESS_KEYWORDS="TGljZW5zZSB2YWxpZGF0aW9uIGZhaWx1cmUgLSBJbnZhbGlkIEtleSBvciBSZWdpc3RyYXRpb24gTmFtZQ=="
Bash脚本config-generator-monit.sh
CONFIG_FILE="/path/monit.ini"
if [[ -f $CONFIG_FILE ]]; then
. $CONFIG_FILE
else
echo 'Config file not found'
exit 1
fi
echo -e 'Check file file.log with path /path/file.log' >> /etc/monit.conf
if [[ -z $SUPRESS_KEYWORDS ]]
then
echo 'No supression keywords for file.log'
else
echo 'Supressing keywords' $SUPRESS_KEYWORDS
echo -e ' ignore match "'`echo $SUPRESS_KEYWORDS | php -R 'echo base64_decode(preg_quote($argn,"\""));'`'"' >> /etc/monit.conf
fi
echo -e ' if match "ERROR" then alert' >> /etc/monit.conf
我在谷歌搜索可能的解决方案,但没有机会
我希望有人在此之前解决了这个问题