Answer the question
In order to leave comments, you need to log in
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
* * * * * root env - "`cat /var/env.txt`" myscript.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 questionAsk a Question
731 491 924 answers to any question