The number of my Shell study notes the number of configuration entries in the Mysql profile
* this script comes from Mujia.com, and the copyright belongs to the original author *
Purpose of the script: query the number of configuration entries for a configuration item (such as [mysqld]) in the Mysql configuration file my.cnf and output it.
The specific script is as follows:
# *
# Author: tomshen
# QQ: × × ×
# Date: 2019-10-14
# Description: The test script
# Copyright (C): 2019 All rights reserved
# *
# output the name of each configuration segment of the my.cnf configuration file, and the number of configuration items for each configuration segment
FILE_NAME=/etc/my.cnf
Function get_all_segment
{
# get all segments
Declare-a mysql_array=$ (sed-n'/ [. *] / p'$FILE_NAME | sed-e's / [/ / g' | sed-e's /] / / g')
For var1 in ${mysql_array [@]}
Do
Echo "$var1"
Done
Unset var1
Unset mysql_aeeay
}
Function count_items_in_segment
{
# get the number of lines of the configuration entry for each configuration segment
Items=$ (sed-n "/\ [$1\] /, /\ [. *] / p" $FILE_NAME | grep-v ^ # | grep-v ^ $| grep-v "\ [. *\]") index=0 for item in $items do index= `expr $index + 1`expr $index
}
Number=0
For segment in get_all_segment
Do
Number=expr $number + 1
Items_count=count_items_in_segment $segment
Echo "$number. Configuration items: $segment configuration entries: $items_count"
Done