MY.CNF configuration format is as follows
VI my.cnf
[Client]
port=3306
Socket=/tmp/mysql.socket
[Mysqld]
port=3306
Server-id=1
Datadir=/usr/local/mysql/data
[Mysqld_safe]
port=3306
More parsemy.sh
#!/bin/bash
cnf=$ (CD ' DirName;p wd) "/MY.CNF"
#得到区块数组
g_sec= (' sed-n '/\[*\]/p ' $cnf |grep-v ' ^# ' |tr-d [] ')
#sed-n '/\[*\]/p ' to get rows containing [*]
#grep-V ' ^# ' removes the line from the #
#tr-D [] remove []
#g_sec = (client mysqld mysqld_safe)
For ((i=0;i<${#g_sec [@]};i++))
Do
echo "Parse No." $i
Sec_name=${g_sec[i]}
g_names= (' sed-n '/\[' $sec _name ' \]/,/\[/p ' $cnf |grep-ev ' \[|\]|^$|^# ' |awk-f ' = ' {print '} ')
#sed-n '/\[' $sec _name ' \]/,/\[/p ' Get all lines from [$sec _name] to near [
#grep-ev ' \[|\]|^$|^# ' remove rows containing [or] removing empty lines minus #
#awk-F ' = ' {print '} ' gets the = number preceding character
g_values= (' sed-n '/\[' $sec _name ' \]/,/\[/p ' $cnf |grep-ev ' \[|\]|^$|^# ' |awk-f ' = ' {print $} ')
#awk-F ' = ' {print '} ' get = sign after character
For ((j=0;j<${#g_names [@]};j++))
Do
echo ${g_names[$j]} "${g_values[$j]}
Done
Done
Shell parsing my.cnf configuration file