一、介绍
这个命令用于操纵配置文件(ini或conf等)的变量,就是修改配置文件,多用来操纵openstack的配置文件。
格式:
crudini --set [OPTION]... config_file section [param] [value]
crudini --get [OPTION]... config_file [section] [param]
crudini --del [OPTION]... config_file section [param] [list value]
crudini --merge [OPTION]... config_file [section]
二、实例演示
以--set为例
confile是配置文件所在的URL,section表示变量所在的部分,param表示所在部分的配置参数,value就是参数的值。
创建一个用于测试的配置文件
[root@controller ~]# vi test.conf
[1]
host=
user=
passwd=
[2]
host=
user=
passwd=
使用set参数在配置文件中[1]的host参数指定一个值,再添加一行email的参数。
[root@controller ~]# crudini --set test.conf 1 host xx
[root@controller ~]# crudini --set test.conf 1 email 1@163.com
[root@controller ~]# cat test.conf
[1]
host=xx
user=
passwd=
email = 1@163.com
[2]
host=
user=
passwd=
使用get参数获取[1]host的值,用del删除[2]的host参数。
[root@controller ~]# crudini --get test.conf 1 host
xx
[root@controller ~]# crudini --del test.conf 2 host
[root@controller ~]# cat test.conf
[1]
host=xx
user=
passwd=
email = 1@163.com
[2]
user=
passwd=
对于没有section的配置文件,则section用一个空字符''表示,下面以selinux的配置文件为例。
[root@controller ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX=permissive
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@controller ~]# crudini --set /etc/selinux/config '' SELINUX enforcing
[root@controller ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX=permissive
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted