How to set a multiline parameter with Moodle CLI cfg.php

How to set a multiline parameter with Moodle CLI cfg.php

by SwissTico Web -
Number of replies: 1

Hello!

We want to script a Moodle configuration and found how to set Moodle (3.9) in CLI with the admin/cfg.php --name=xxx --set=xxx

However we have an issue with multiline parameters like Site administration > Security > IP blocker where the Blocked IP List need to be one IP per line.

We tried many different ways and options (--shell-arg, --json, etc.) , but we couldn't find the way to have it multiline. For instance, if we use the \n or \r\n escape, it literally write "\r\n" and we get the result in the web administration:

172.16.0.0/12\r\n192.168.0.0/16
instead of
172.16.0.0/12
192.168.0.0/16

How can we fix this issue?

Thanks for your help!

Average of ratings: -
In reply to SwissTico Web

Re: How to set a multiline parameter with Moodle CLI cfg.php

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

I think this is a Bash issue so I used this StackOverflow answer which worked for me:

ip=$'172.16.3\r\n172.16.4'
php admin/cli/cfg.php --name=blockedip --set="$ip"

The use of single and double quotes is important of course.


Average of ratings: Useful (1)