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:
laverya@laverya-script-testing:~$ cat test.sh
#/bin/bash
replicatedctl app-config export > settings.json
replicatedctl app-config import < settings.json
laverya@laverya-script-testing:~$ ./test.sh
Settings import success
laverya@laverya-script-testing:~$ ./test.sh > test.out
Error: decode json: EOF
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:
laverya@laverya-script-testing:~$ cat test.sh
#/bin/bash
replicatedctl app-config export > settings.json
replicatedctl -i app-config import < settings.json
laverya@laverya-script-testing:~$ ./test.sh
Settings import success
laverya@laverya-script-testing:~$ ./test.sh > test.out
laverya@laverya-script-testing:~$ cat test.out
Settings import success
laverya@laverya-script-testing:~$
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!