Dans un précédent post, j'avais écrit un petit script pour manipuler les fichier ini en bash.
Il existe un utilitaire python permettant de faire ceci de manière plus propre. Il s'agit de crudini
Pour l'installer, depuis Debian Wheezy, installer pip pour python :
sudo apt-get install python-pip
Puis, l'utilitaire proprement dit :
pip install crudini
Voici son help :
One of --set|--del|--get|--merge must be specified
A utility for manipulating ini files
Usage: crudini --set [OPTION]... config_file section [param] [value]
or: crudini --get [OPTION]... config_file [section] [param]
or: crudini --del [OPTION]... config_file section [param] [list value]
or: crudini --merge [OPTION]... config_file [section]
Options:
--existing[=WHAT] For --set, --del and --merge, fail if item is missing,
where WHAT is 'file', 'section', or 'param', or if
not specified; all specifed items.
--format=FMT For --get, select the output FMT.
Formats are sh,ini,lines
--inplace Lock and write files in place.
This is not atomic but has less restrictions
than the default replacement method.
--list For --set and --del, update a list (set) of values
--list-sep=STR Delimit list values with "STR" instead of " ,"
--output=FILE Write output to FILE instead. '-' means stdout
--verbose Indicate on stderr if changes were made
On peut l'utiliser de cette manière :
└▶ cat /etc/php5/conf.d/20-apc.ini
extension=apc.so
apc.shm_size = 2G
└▶ sudo crudini --set /etc/php5/conf.d/20-apc.ini '' apc.shm_size 1G
└▶ cat /etc/php5/conf.d/20-apc.ini
extension=apc.so
apc.shm_size = 1G
Notez que le '' spécifie une section vide.