Script don't recognize strings (Docker Windows) - windows

I have an exe file which executing some commands in docker container (ubuntu) that should make a build and run application. In some step I need to make a copy of dist file and command looks like this
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v //f/bigaboo/repos/ledger://f/bigaboo/repos/ledger --workdir=//f/bigaboo/repos/ledger bbcli_executor bash -c "cp ./public/index.php.dist ./public/index.php"
When I just run this command in the terminal all works well but if it's under exe control I have this output
./public/index.php.dist: -c: line 1: unexpected EOF while looking for matching `"'
./public/index.php.dist: -c: line 2: syntax error: unexpected end of file
2022/10/31 22:14:42 Failed to create index.php`. Error -> exit status 2
Looks like script don't recognize strings under exe.
I've tried to wrap cp in '',`` and \x22 but I've got the same result but with different symbols also I've tried to change encoding also without success :(

Related

Execute command inside a bash script with space inside parameter

I'm having the following issue. When I execute this command sfdx profile:field:add -n "Account.Test" -m re -p "Test" from a Bash script, it's all fine.
However, when I try to execute the following:
sfdx profile:field:add -n "Account.Test" -m re -p "Test Test"
I get this error: 'C:\Program' is not recognized as an internal or external command
When I run the same command in the terminal, it works fine. It's just when I put it inside a bash script that this error happens.
Currently running this on Windows 10.
I'm 100% sure it's the space in that last parameter, I am just not sure how to get around it. Can anyone help?

Process substitution command in . ebextensions

I'm trying to install Netdata in my aws beanstalk instances. I created a config file in my .ebextensions folder
container_commands:
00install:
command: "bash <(curl -Ss https://my-netdata.io/kickstart.sh) --dont-wait"
ignoreErrors: true
When the command gets ran on deploy beanstalk logs this error.
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `bash <(curl -Ss https://my-netdata.io/kickstart.sh) --dont-wait'
I had no idea what <() meant so I looked it up and saw it was process substitution. From what I understood process substitution can be rewriting using plain pipes.
For example
more <( ls /usr/bin )
Could be
ls /usr/bin | more
In my command I'm also passing in flags so I was having issues gettin the piped version of the command working.
NOTE: The root problem is beanstalk telling me its confused about the parenthesis. My solution was just transforming the command to use regular pipes. However, if anyone knows just how I write this command on the beanstalk config to get it working that would be awesome.

Shell Script failing on alpine linux while working in mac terminal

The following line fails when run in a alpine docker container:
toDelete=( $(curl --silent $url/_cat/indices\?format=json | jq -r '.[].index | select(startswith('\".kibana\"'))') )
The following error message appears:
run.sh: line 1: syntax error: unexpected "("
When I run the command in the terminal on my mac, everything works properly. The brackets are added so that the result (variable toDelete) is interpreted as array and can be looped through with a for loop like so:
for index in "${toDelete[#]}"; do
curl -X DELETE $url/$index
done
Any help in how to solve this problem is appreciated!
Marking down the answer.
The issue was with the interpreter.
worked after making the below change.
["/bin/ash", "run.sh"]
the passed one was
["/bin/sh", "run.sh"]

I am having trouble running a bash script that opens docker container in interactive mode and eexcute some commands

I am using next commands to open a docker container in interactive mode and using following commans inside bash session with this container.
docker run -v /scriptsIA:/scriptsIA -v /opt/tomcat/webapps/PokeTrainer/imgIA:/imgsIA -it dbmobilelife/docker-python-opencv-tesseract bash
cd /scriptsIA/
python
from SegmentarImagen import *
extraerNombreUsuarioNiveldeUnaFoto("/imgsIA/andres.jpg")
exit()
exit
I have tried to create a bash script as follows:
#!/bin/bash
docker run -v /scriptsIA:/scriptsIA -v /opt/tomcat/webapps/PokeTrainer/imgIA:/imgsIA -it dbmobilelife/docker-python-opencv-tesseract bash
cd /scriptsIA/
python
from SegmentarImagen import *
extraerNombreUsuarioNiveldeUnaFoto("/imgsIA/andres.jpg")
exit()
exit
However, when i execute this bash script all i get is the following error:
[root#poketrainer /]# sh scriptIA.sh docker: Error response from
daemon: OCI runtime create failed: container_linux.go:344: starting
container process caused "exec: \"bash\r\": executable file not found
in $PATH": unknown. : No existe el fichero o el directorio
scriptIA.sh: línea 4: $'python\r': no se encontró la orden
scriptIA.sh: línea 5: from: no se encontró la orden scriptIA.sh: línea
6: error sintáctico cerca del elemento inesperado
"/imgsIA/andres.jpg"' 'criptIA.sh: línea 6:
extraerNombreUsuarioNiveldeUnaFoto("/imgsIA/andres.jpg")
How can I do the explained bash script above withouth getting errors?
There are multiple issues with your script here:
The \r errors such as:
starting container process caused "exec: \"bash\r\": executable file not found in $PATH": unknown
And other similar errors are related: the \r indicates there is a Windows carriage return in your script - it was probably written on Windows and mounted in a VM, or your editor somehow added these characters (see this post). Linux only expects a \n and treats \ras part of your command. Try running dos2unix on your file or make sure there are no special characters.
Also, the script has several issues:
You are trying to run docker exec which runs a bash command which cd and runs a python script. This can be simplified a bit (see below)
You want to run Python, there is probably no need to run bash first, you can run python command directly
Given that you want to run 2 Python commands you'll require line breaks, that's possible but not very handy. It would be better to create a Python script and mount it in the image before running a simple python command.
It would also be better to use docker exec -w flag instead of using cd command to set working directory
There is no need for exit nor exit() as it will be done implicitly once there are no more instructions to be executed
Given all that, you can:
run a single command such as
docker exec [...] -it -w /scriptsIA dbmobilelife/docker-python-opencv-tesseract \
echo -e "from SegmentarImagen import *\nextraerNombreUsuarioNiveldeUnaFoto("/imgsIA/andres.jpg")" | python
in which you set working directory with -w and run a Python command by passing its content via echo and a pipe (mind the \n with no space to have a proper Python syntax)
creating a myscript.py script such as:
from SegmentarImagen import *
extraerNombreUsuarioNiveldeUnaFoto("/imgsIA/andres.jpg")
then mount that script into the container and run a simple python command:
docker exec [...] -it -w /scriptsIA -v /path/to/myscript.py:/myscript.py \
dbmobilelife/docker-python-opencv-tesseract \
python /myscript.py
Note: the [...] are for the -v /scriptsIA:/scriptsIA -v /opt/tomcat/webapps/PokeTrainer/imgIA:/imgsIA volume mount I cut out for simplification

JSBuilder - trouble with command line build

I have a Sencha Touch application I am trying use JSBuilder to build which I am running this script in my Terminal:
bash JSBuilder.sh -v -p airside.jsb3 -d .\AirSide
But I am receiving this error:
JSBuilder.sh: line 11: ./jsdb/mac/jsdb: Permission denied
I am not sure how to fix this or what I am doing wrong?
Try putting sudo in front of the bash

Resources