Calling bash script inside AWS CodeBuild: script could not be found - bash

I'm trying to run a small bash script inside my CodeBuild process as per the AWS documentation and this.
deploy.sh can be found in the src/ directory:
#!/bin/bash
pwd=$PWD
for dir in */ ; do
target="$pwd/${dir%/}"
cd "$target"
npm install
sls deploy && sls s3deploy
done
buildspec file:
version: 0.2
phases:
install:
runtime-versions:
nodejs: 10
commands:
- cd backend/functions/src
- npm install serverless
build:
commands:
- ls
- ./deploy.sh
after the ls command above in the logs, I can see that deploy.sh is there in the current directory.
Error:
/codebuild/output/tmp/script.sh: 4: /codebuild/output/tmp/script.sh: ./deploy.sh: not found
I've also tried using the command /bin/bash deploy.sh but this results in another error:
deploy.sh: line 2: $'\r': command not found
deploy.sh: line 4: $'\r': command not found
deploy.sh: line 7: $'\r': command not found
deploy.sh: line 8: syntax error near unexpected token `$'do\r''
deploy.sh: line 8: `for dir in */ ; do

(First written as a comment, it solved the problem)
The files were made in Windows.
Change CRLF to LF and the \r is gone.

The first answer by Walter A worked for me, this is what i did .
Opened the file in VS Code
At bottom left corner for Select End Of Line Sequence it showed CRLF
clicked on CRLF and selected LF
Uploaded the file to github and it started working.

Related

Script don't recognize strings (Docker 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 :(

Starting expo project failed: ps and grep commands not found

I tried running my expo project for the first time on a new M1 Pro mac. I obtained the following error logs. For context, I am using the fish shell. What is wrong? Are ps and grep obtained through some package(s)?
bananas#MacBook-Pro ~/E/myproject [254]> expo start
WARNING: expo-cli has not yet been tested against Node.js v17.0.1.
If you encounter any issues, please report them to https://github.com/expo/expo-cli/issues
expo-cli supports following Node.js versions:
* >=12.13.0 <13.0.0 (Maintenance LTS)
* >=14.0.0 <15.0.0 (Active LTS)
* >=15.0.0 <17.0.0 (Current Release)
Starting project at /Users/williama/Experiments/prpool
Developer tools running on http://localhost:19002
Opening developer tools in the browser...
/bin/sh: ps: command not found
/bin/sh: grep: command not found
/bin/sh: ps: command not found
/bin/sh: grep: command not found
/bin/sh: ps: command not found
/bin/sh: grep: command not found
/bin/sh: ps: command not found
/bin/sh: grep: command not found
/bin/sh: ps: command not found
/bin/sh: grep: command not found
/bin/sh: ps: command not found
/bin/sh: grep: command not found
Error: spawn open ENOENT
at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
at onErrorNT (node:internal/child_process:475:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
I did not have my PATH set up properly.
Before, I had
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin"
export PATH=$ANDROID_HOME/platform-tools
I realized that the last line was overwriting my PATH variable and throwing away everything set on the first line, since the I was not using the $PATH reference (notice the dollar sign) on the second definition.
export PATH="$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin"

TensorFlow installation - pip

I am following this guide to install pip: https://www.tensorflow.org/install/pip
When I run this command: . ./venv/bin/activate.fish
I get the following error:
-bash: ./venv/bin/activate.fish: line 4: syntax error near unexpected token -d'
-bash: ./venv/bin/activate.fish: line 4:function deactivate -d "Exit virtualenv and return to normal shell environment"'
Please assist.
thanks
The script activate.fish is intended for fish shell. You're running bash so it's a wrong script for bash. With bash use activate:
. ./venv/bin/activate
The command should be
$ source ./venv/bin/activate
if you are using bash in a Linux machine.

Starting bash script on Docker container startup doesn't work

For the last couple of hours I have been trying to start my startup.sh script on docker container start, but for some reason it doesn't work.
My Dockerfile to create the image:
FROM armv7/armhf-ubuntu:latest
MAINTAINER Mohammed Noureldin <m.n.e#hotmail.com>
RUN apt update && apt upgrade -y && apt install -y mumble-server
ADD scripts/startup.sh /startup.sh
My startup script:
#!/bin/bash
/etc/init.d/mumble-server start
Nothing happens here, though I tried to create a file inside the script but also nothing happened!
I tried to execute the script directly from command line, but it doesn't work I don't know why:
docker run command:
docker run --name murmur -itd --restart always --network bridge -p 64738:64738 -v /var/lib/mumble-server/ -v /etc/ mnoureldin/murmur:latest /bin/bash -c "bash /startup.sh;/bin/bash"
And here what I get when trying to execute the script manually:
43b9d8dd4116bc605537c7af35ab186ca165ea6e957fab5908d39b2f085edf41
mohammed#server01:~/Dockerfiles/Mumble $ docker attach murmur
root#43b9d8dd4116:/# bash
.dockerenv boot/ etc/ lib/ mnt/ proc/ run/ srv/ sys/ usr/
bin/ dev/ home/ media/ opt/ root/ sbin/ startup.sh tmp/ var/
root#43b9d8dd4116:/# bash startup.sh
Usage: /etc/init.d/mumble-server {start|stop|restart|force-reload}
Or when I have an empty line between the two lines of the script I get this error:
root#830193e67fd7:/# bash startup.sh
startup.sh: line 2: $'\r': command not found
Usage: /etc/init.d/mumble-server {start|stop|restart|force-reload}
Could some one explain what is heppening and why it doesn't work?
The error is caused by the line endings in your shell script. It looks like you're using Windows line endings (CRLF, or \r\n), where the unexpected r is confusing Bash. Bash only expects LF or \n, hence the error message.
Most programmer text editors have some kind of support for making these changes. Notepad++ has "Edit > EOL Conversion > Unix/OSX Format". Please see EOL conversion in notepad ++ for more info.

Ubuntu BASH syntax error near unexpected token

I'm following this tutorial http://ubuntuforums.org/showthread.php?t=1550470 to install a GUI for Phorinix test suite installing it on Ubuntu 12.04. I already have the test suite and PHP5 installed, both running fine in the terminal but I'm now trying to create the GUI.
When running this part of the tutorial:
cd /usr/share/aclocal
sudo cp libtool.m4 libtool.m4~backup
sudo chmod 777 libtool.m4
(start line) sudo cat lt~obsolete.m4 ltoptions.m4 ltsugar.m4 ltversion.m4 >>libtool.m4 (end line)
sudo chmod 644 libtool.m4
I get the following error:
bash: syntax error near unexpected token `sudo'
Any ideas?
The (start line) and (end line) markers look more like comments than they do commands that fit the rest of the script. But if they really belong, they need to be separated from the rest of the line with
(start line); sudo cat ... >> libtool.m4; (end line)
Remove the (start line) and (end line). The original poster added these when the forum would cut off lines in order to fit code blocks in a certain width.

Resources