#!/bin/bash # Author: Ričardas Stoma # Company: Kolmisoft # Year: 2016 # About: Disable MySQL secure_file_priv for LOAD_FILE function . /usr/src/m2/framework/bash_functions.sh DB_PASSWORD=`cat /etc/m2/system.conf | grep dbsecret | awk '{print $3}'` DB_USERNAME=`cat /etc/m2/system.conf | grep dbuser | awk '{print $3}'` DB_NAME=`cat /etc/m2/system.conf | grep dbname | awk '{print $3}'` DB_HOST=`cat /etc/m2/system.conf | grep dbhost | awk '{print $3}'` function check_variable() { local secure_file_priv_variable=`grep -F 'secure_file_priv' /etc/my.cnf` if [ "$secure_file_priv_variable" == "secure_file_priv=" ]; then # check if mysql has correct value local mysql_variable_value=`mysql -h $DB_HOST $DB_NAME -u $DB_USERNAME -p$DB_PASSWORD -e "SHOW VARIABLES" | grep secure_file_priv | awk '{print $2}'` if [ "$mysql_variable_value" != "" ]; then report "Variable secure_file_priv in /etc/my.cnf file is different from the one loaded in MySQL. Please restart MySQL when convenient" 3 else report "MySQL variable secure_file_priv has correct value" 0 fi return 0 else return 1 fi } # Check if my.cnf exists if [ ! -f "/etc/my.cnf" ]; then exit 0 fi check_variable if [ $? == 1 ]; then report "MySQL variable secure_file_priv has incorrect value or is missing" 2 # delete line where secure_file_priv is set sed -i '/secure_file_priv/d' /etc/my.cnf # add correct value sed -i "s|\[mysqld\]|\[mysqld\]\nsecure_file_priv=|" /etc/my.cnf report "Variable is fixed" 0 # restart MySQL (if running in install script) if [ "$1" == "INSTALL" ]; then report "Restarting MySQL" 3 service mysqld restart fi # check again check_variable fi exit 0