How can I import app settings within a script?


#1

I need to run replicatedctl app-config import < settings.json from within a script, but whenever I use output redirection for the script things break. How can I avoid this?

Here’s a minimal example:

[email protected]:~$ cat test.sh
#/bin/bash

replicatedctl app-config export > settings.json
replicatedctl app-config import < settings.json

[email protected]:~$ ./test.sh
Settings import success
[email protected]:~$ ./test.sh > test.out
Error: decode json: EOF

#2

There are several flags that can be provided to replicatedctl that determine how input is passed to the docker exec (or kubectl exec, depending on scheduler), though the relevant one for this issue is -i. If this flag is present, the replicatedctl script will pass it on to docker - where it enables listening to the input stream.

Like this:

[email protected]:~$ cat test.sh
#/bin/bash

replicatedctl app-config export > settings.json
replicatedctl -i app-config import < settings.json

[email protected]:~$ ./test.sh
Settings import success
[email protected]:~$ ./test.sh > test.out
[email protected]:~$ cat test.out
Settings import success
[email protected]:~$

There’s a few of these - -i, -t, --no-tty - you can view them all with cat $(which replicatedctl). We do our best to determine the appropriate set of docker flags, but you can always override them when things break!