- 论坛徽章:
- 0
|
本帖最后由 wesk2730top 于 2019-05-04 21:08 编辑
ansible没用过,不过就楼主提的三点问题回答一下。
1.获取配置文件列表名
# grep '^\[.*\]$' my.cnf #获取my.cnf列表名称
2.获取指定列表内容,# sh test.sh my.cnf mysqld #执行脚本,位置变量1为配置文件,2为列表名
[root@mysql ~]# cat test.sh
#!/bin/bash
a=$2
b=`grep '\[.*\]' $1 | sed 's/\[//;s/\]//' | grep -A1 "^$2$" | grep -v "^$2$"`
sed -n "/\[$a\]/,/\[$b\]/p" $1 | awk 'NR>1' | sed '$d'
c=`grep '^\[.*\]$' my.cnf | sed 's/\[//;s/\]//' | tail -1`
if [ $2 == $c ]
then
tail -1 $1
fi
3.调用指定内容,for循环,每行后面加“===”
[root@mysql ~]# cat test1.sh
#!/bin/bash
for i in `sh test.sh $1 $2`
do echo "$i==="
done
|
|