running commands or script lines simple tests, -e
, in vagrant
using ssh
subcommand works fine (e.g.
vagrant ssh -c 'if ! [ -e file.deb ] ; wget http://a.b/file.deb; fi'
as string comparison , command execution bash
quoting gets involved, complexity rises sky. tried
- escaping strings, doesn't seem work in general (complexity of escaping of escaping of escaping ... in
bash
inacceptable) writing in script file
cat <<eof > file [code]eof
idiom, e.g.vagrant ssh -c 'cat <<eof > fetch.sh \ #!/bin/bash \ if [ "$(md5sum file.deb | cut -d \" \" -f 1)" != "d757d51819f8f945ae7715b532ab8d2e" ] ; wget http://a/b/file.deb; fi \ eof' vagrant ssh -c 'bash ./fetch.sh'
causes
./fetch.sh: line 1: syntax error near unexpected token `if'
- the failure of
cat eof
idiom implies failure of sort of script created invagrant
(python
,groovy
, etc. suffer same incapacity ofbash
provide usable string quoting/be usable @ all)
is there way execute script code complex statements in tests inside vagrant
box? need transfer script via localhost interface (using ftp or similar)?
with knowledge of how use ssh run shell script on remote machine? it's possible connect vagrant using
ssh -p [port] -i [keyfile] vagrant@localhost 'bash -s' < script.sh
(with [port]
, [keyfile]
retrieved vagrant ssh-config
) , script code put in script.sh
.
the port can change if multiple vagrant
instances running (each starting own ssh server), might need parse vagrant ssh-config
.
Comments
Post a Comment