moxi
October 17, 2021, 8:08pm
1
I try to use some auto-configuration for qubes in dom0 like this:
qvm-run my-qube 'cat <<EOF >> /rw/config/rc.local
systemctl start myservice
EOF'
But get error:
Running ‘cat <<EOF >> /rw/config/rc.local
systemctl start myservice
EOF’ on my-qube
my-qube: command failed with code: 1
The EOF
terminator apparently is not parsed properly.
Substituting qvm-run
with bash
works alls fine:
bash -c 'cat <<EOF >> /rw/config/rc.local
systemctl start myservice
EOF'
Is there any way to escape here documents properly with qvm-run?
This should work:
bash_code='cat <<EOF >> /rw/config/rc.local
systemctl start myservice
EOF'
qvm-run --pass-io --user=root --service my-qube qubes.VMShell <<<"$bash_code"
1 Like
moxi
October 18, 2021, 12:05pm
3
Yes, this works - thanks!
I still have hoped for a solution, which does get rid of passing stdin/stdout between dom0 and qubes.
After tried out some workaround, I am now copying the script and execute it remotely on the target qube.
This also get syntax highlighting of the shell code used to be contained in the here doc.
Just combine the two, qvm-run
and bash -c
:
qvm-run -p qube "/bin/bash -c '
cat <<EOF >> /rw/config/rc.local
systemctl start myservice
EOF
'"
1 Like
moxi
October 21, 2021, 12:17pm
6
You are a genius, thanks!
Now I can ditch manual copying the scripts to remote and directly pass the script as
qvm-run qube "/bin/bash -c \"$(cat /path/to/script/with/here/doc)\""
You don’t even need to pass io (-p
) for extra safety.