G
G
ghostku2015-07-04 21:40:43
bash
ghostku, 2015-07-04 21:40:43

How to use env to substitute environment variables that have spaces?

There is a docker, there is cron in docker and a known problem when, when running a script with cron, the script does not receive the environment variables set when the container was started. There is also a solution to do when starting the container:
env /var/env.txt
and in crontab write something like

* * * * * root env - `cat /var/env.txt` myscript.sh

But the problem is that there are problems in the value of my variables and when loading them from the env file it trips over them and crashes. I tried to do like this:
* * * * * root env - "`cat /var/env.txt`" myscript.sh

I've tried seding and putting quotes at the beginning and end of every line in the /var/env.txt file - it doesn't help how to properly escape those damn spaces.
Thank you.
UPD What I have tried
is test.sh
[email protected]:/# env | grep "VAR1"
VAR1=HA HA HA
[email protected]:/# env > /home/test/env.txt
[email protected]:/# cat /home/test/env.txt | grep "VAR1"
VAR1=HA HA HA
[email protected]:/# env -i "VAR1=HA HA HA" /home/test/test.sh
VAR1=HA HA HA
[email protected]:/# env -i `cat /home/test/env.txt` /home/test/test.sh
env: 1049: No such file or directory
[email protected]:/# exit
exit
[email protected]:~$ docker run  -it -v /var/nod32:/var/www/html/nod32 ghostku/nod32 /bin/bash
[email protected]:/# env | grep "VAR1"
VAR1=HA HA HA
[email protected]:/# env > /home/test/
build.sh  tada.sh   test.sh
[email protected]:/# env > /home/test/env.txt
[email protected]:/# cat /home/test/env.txt | grep "VAR1"
VAR1=HA HA HA
[email protected]:/# env -i "VAR1=HA HA HA" /home/test/test.sh
VAR1=HA HA HA
[email protected]:/# env -i `cat /home/test/env.txt` /home/test/test.sh
<b>env: HA: No such file or directory</b>
[email protected]:/# sed -e 's/^/"/g' -e 's/$/"/g' /home/test/env.txt > /home/test/env1.txt
[email protected]:/# cat /home/test/env1.txt | grep "VAR1"
"VAR1=HA HA HA"
[email protected]:/# env -i `cat /home/test/env1.txt` /home/test/test.sh
<b>env: HA: No such file or directory</b>
[email protected]:/# sed -e 's/=/="/g' -e 's/$/"/g' /home/test/env.txt > /home/test/env2.txt
[email protected]:/# cat /home/test/env2.txt | grep "VAR1"
VAR1="HA HA HA"
[email protected]:/# env -i `cat /home/test/env2.txt` /home/test/test.sh
<b>env: HA: No such file or directory</b>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question