What is "delimited by end-of-file (wanted `EOF')" - bash

I am trying to execute following lines-
sh """
#!/bin/bash
cd ${WORKSPACE}
cat << EOF > build.sh
#!/bin/bash
mkdir wsbuildlinux
cd wsbuildlinux
cmake3 ../../wiresharkbuild_linux
make
EOF
chmod 755 build.sh
# run container and build wireshark
./build-env/run-wireshark-env ./build.sh
"""
and here is the content of "build.sh"-
#!/bin/bash
mkdir wsbuildlinux
cd wsbuildlinux
cmake3 ../../wiresharkbuild_linux
make
EOF
chmod 755 build.sh
# run container and build wireshark
./build-env/run-wireshark-env ./build.sh
But I keep getting following error-
/opt/cvsdirs/crdbuilds/jenkins/slave/workspace/Wireshark_Wireshark_trunk#tmp/durable-f510f070/script.sh: line 17: warning: here-document at line 5 delimited by end-of-file (wanted `EOF')
I have no idea what this error means and how to resolve it. Could you please give some advice on this

The EOF token has to be at the beginning of the line.
sh """
#!/bin/bash
cd ${WORKSPACE}
cat << EOF > build.sh
#!/bin/bash
mkdir wsbuildlinux
cd wsbuildlinux
cmake3 ../../wiresharkbuild_linux
make
EOF
chmod 755 build.sh
# run container and build wireshark
./build-env/run-wireshark-env ./build.sh
"""

Related

Docker container unable to ignore the EntryPoint bash script failure

Bash script:
clonePath=/data/config/
git branch -r | fgrep -v 'origin/HEAD' | sed 's| origin/|git checkout |' > checkoutAllBranches.sh
chmod +x checkoutAllBranches.sh
echo "Fetch branch: `cat checkoutAllBranches.sh`"
./checkoutAllBranches.sh
git checkout master
git remote rm origin
rm checkoutAllBranches.sh
for config_dir in `ls -a`; do
cp -r $config_dir $clonePath/;
done
echo "API Config update complete..."
Dockerfile which issues this script execution
ENTRYPOINT ["sh","config-update-force.sh","|| true"]
The error below causes the container startup failure despite setting the command status to 0 manually using || true
ERROR:
Error:
cp: cannot create regular file '/data/./.git/objects/pack/pack-27a9d...fb5e368e4cf.pack': Permission denied
cp: cannot create regular file '/data/./.git/objects/pack/pack-27a9d...fbae25e368e4cf.idx': Permission denied
I am looking for 2 options here:
Change these file permissions and then store them in the remote with rwx permissions
Do something to the docker file to ignore this script failure error and start the container.
DOCKERFILE:
FROM docker.hub.com/java11-temurin:latest
USER root
RUN apt-get update
RUN apt-get -y upgrade
RUN apt-get install -y rsync telnet vim wget git
RUN mkdir -p /opt/config/clone/data
RUN chown -R 1001:1001 /opt/config
USER 1001
ADD build/libs/my-api-config-server.jar .
ADD config-update-force.sh .
USER root
RUN chmod +x config-update-force.sh
USER 1001
EXPOSE 8080
CMD java $BASE_JAVA_OPTS $JAVA_OPTS -jar my-api-config-server.jar
ENTRYPOINT ["sh","config-update-force.sh","|| true"]
BASH SCRIPT:
#!/bin/bash
set +e
set +x
clonePath=/opt/clone/data/data
#source Optumfile.properties
echo "properties loaded: example ${git_host}"
if [ -d my-api-config ]; then
rm -rf my-api-config;
echo "existing my-api-config dir deleted..."
fi
git_url=https://github.com/my-api-config-server
git clone https://github.com/my-api-config-server
cd my-api-config-server
git branch -r | fgrep -v 'origin/HEAD' | sed 's| origin/|git checkout |' > checkoutAllBranches.sh
chmod +x checkoutAllBranches.sh
echo "Fetch branch: `cat checkoutAllBranches.sh`"
./checkoutAllBranches.sh
git checkout master
git remote rm origin
rm checkoutAllBranches.sh
for config_dir in `ls -a`; do
cp -r $config_dir $clonePath/;
done
echo "My API Config update complete..."
When you do in the script...
chmod +x checkoutAllBranches.sh
...than why not before cp
chmod -R +rwx ${clonePath}
...or if the stderr message 'wont impact anything'...
cp -r $config_dir $clonePath/ 2>/dev/null;
...even cp dont copy -verbosly.
?
When your Dockerfile declares an ENTRYPOINT, that command is the only thing the container does. If it also declares a CMD, the CMD is passed as additional arguments to the ENTRYPOINT; it is not run on its own unless the ENTRYPOINT makes sure to execute it.
Shell errors are not normally fatal, and especially if you explicitly set +e, even if a shell command fails the shell script will keep running. You see this in your output where you get multiple cp errors; the first error does not terminate the script.
You need to do two things here. The first is to set the ENTRYPOINT to actually run the CMD; the simplest and most common way to do this is to end the script with
exec "$#"
The second is to remove the || true from the Dockerfile. As you have it written out currently, this is passed as the first argument to the entrypoint wrapper – it is not run through a shell and it is not interpreted as a "or" operator. If your script begins with a "shebang" line and is marked executable (both of these are correct in the question) the you do not explicitly need the sh interpreter.
# must be a JSON array; no additional "|| true" argument; no sh -c wrapper
ENTRYPOINT ["./config-update-force.sh"]
# any valid CMD will work with `exec "$#"
CMD java $BASE_JAVA_OPTS $JAVA_OPTS -jar my-api-config-server.jar

permission denied with yapf in ssh script because of make

I have this strange error : i have a makefile with a format target that runs yapf -ir -vv --style pep8 .
When I ssh log as user into my debian 11 server and run make format it works. When i run sudo make format i get the error
yapf -ir -vv --style pep8 .
make: yapf: No such file or directory
make: *** [makefile:5: format] Error 127
When i run a ssh script from my local machine that logs to the server and runs with the line make format, i get the following error :
yapf -ir -vv --style pep8 .
make: yapf: Permission denied
make: *** [makefile:5: format] Error 127
I also get similar output for linting:
/bin/sh: 1: pylint: Permission denied
make: *** [makefile:7: lint] Error 127
I've tried to change the owner with chown to my user, i've tried to make read and write permissions to user, group and other and it's the same...so i suspect it's a sudo thing but i'm not sure.
The user belongs to sudo group but i'm confused why the script doesnt work and it works manually...
The script is like this :
ssh -p 4444 -i /mykey user#ip << 'ENDSSH'
echo 'deploying zabbix'
cd /zabbix && docker-compose up -d
echo 'zabbix deployed'
echo 'copying zabbix module to container'
sudo mkdir -p /var/lib/zabbix/modules/dockermodule
docker cp /zabbix/zabbix_module_docker.so zabbixserver:/var/lib/zabbix/modules/dockermodule
echo 'copied zabbix module to container done'
echo 'extracting tar file'
sudo rm -rf /app/* && sudo tar -xf /tmp/project.tar -C /
sudo chown -R user /app
sudo chmod -R u=rwx /app
echo 'tar file extracted'
echo 'going into app folder'
cd /app
echo 'getting rid of hidden macos files'
sudo find . -type f -name '._*' -delete
echo 'hidden macos files deleted'
echo 'running install'
make install
echo 'install done'
echo 'running format'
make format
echo 'format done'
echo 'running lint'
make lint
echo 'lint done'
echo 'running test'
make test
echo 'test done'
#echo 'running vulnerability check'
#trivy fs --security-checks vuln --severity HIGH,CRITICAL / > security_check.txt
#echo 'vuln check done'
echo 'running docker build & run'
make docker
echo 'docker built and running'
ENDSSH
the make commands are :
make format:
yapf -ir -vv --style pep8 .
make lint:
cd ..; pylint app --verbose --disable=R,C -sy
The commands are not failing when i replave make format or make lint with the commands they run in my script...

Problem of RUN shell script in Dockerfile in Mac OS X

I'm trying to use Docker with my macOS Catalina v10.15.4
When I tried to RUN ./test.sh in Dockerfile and there is some error occured.
This is my Dockerfile:
FROM ubuntu:18.04
RUN mkdir -p /home/rootfs/src
COPY test.sh /home/rootfs
WORKDIR /home/rootfs
RUN chmod +x test.sh && ./test.sh
When I tried to build this, it did not find the script as below:
$ docker build -t test .
Sending build context to Docker daemon 264.6MB
Step 1/5 : FROM ubuntu:18.04
---> 4e5021d210f6
Step 2/5 : RUN mkdir -p /home/rootfs/src
---> Running in d0813632475d
Removing intermediate container d0813632475d
---> 87a6e284993d
Step 3/5 : COPY test.sh /home/rootfs
---> 26d281d0002c
Step 4/5 : WORKDIR /home/rootfs
---> Running in 4c7e81a514a7
Removing intermediate container 4c7e81a514a7
---> dab2872eb15a
Step 5/5 : RUN chmod +x test.sh && ./test.sh
---> Running in a03f3e5d29b4
/bin/sh: 1: ./test.sh: not found
The command '/bin/sh -c chmod +x test.sh && ./test.sh' returned a non-zero code: 127
I check the info of test.sh file test.sh in macOS.
Got this:
test.sh: POSIX shell script text executable, ASCII text, with CRLF line terminators
Your test.sh script contains Windows line endings as specified in output of file test.sh. Convert them to Unix line endings:
$ dos2unix test.sh
dos2unix: converting file test.sh to Unix format...

basic BASH variable call failing in script

Why is this basic variable call in my script failing?
The script is just below and the errors outputted in terminal after execution are below the script.
Line 8 is the first sudo command.
I am executing this script as root in terminal for now. It works just fine if I execute the commands manually, one-at-a-time, within terminal...
I would be grateful for any insight.
#!/bin/bash
echo Enter username
read NAME
echo Enter number
read NUM
sudo (cd /Users/$NAME && tar c .) | (cd /Users/$NUM && tar xf -)
sudo chown -R $NUM:"Domain Users" /Users/$NUM
sudo chmod g+rwx /Users/$NUM
Stephen-Kucker:Desktop root# ./stackoverflowq.txt
Enter username
jsteinberg-c
Enter number
admin
./stackoverflowq.txt: line 8: syntax error near unexpected token `cd'
./stackoverflowq.txt: line 8: `sudo (cd /Users/$NAME && tar c .) | (cd /Users/$NUM && tar xf -)'
Try this:
sudo tar -C /Users/$NAME -c . | sudo tar -C /Users/$NUM -xf -
You need to use the -s option to pass an arbitrary shell command (like the pipeline shown) to the shell with sudo:
sudo -s "(cd /Users/$NAME && tar c .) | (cd /Users/$NUM && tar xf -)"

Why can't I echo contents into a new file as sudo? [duplicate]

This question already has answers here:
Bash Deployment Script Permission Problem
(2 answers)
Closed 8 years ago.
I came across this weird problem just now and I can't seem to get to the bottom of it. I'm trying to add a config file to /etc/sudoers.d/ but get permission denied. In the example below, the file "tweedle" doesn't exist and:
drwxr-xr-x 2 root root 4.0K Jan 2 18:27 sudoers.d/
So here's the command:
$ sudo echo "tweedle ALL=(ALL) ALL" > /etc/sudoers.d/tweedle
-bash: /etc/sudoers.d/tweedle: Permission denied
It doesn't even work when I break it into two commands:
$ sudo touch /etc/sudoers.d/tweedle
$ sudo echo "poodle" > /etc/sudoers.d/tweedle
When I tested it locally, same problem:
$ cd ~
$ mkdir -m 755 tweedle
$ sudo chown root:root tweedle
$ sudo echo "battle" > ~/tweedle/beetle
-bash: /home/spanky/tweedle/beetle: Permission denied
$ sudo touch tweedle/beetle
$ sudo echo "battle" > tweedle/beetle
-bash: tweedle/beetle: Permission denied
Without sudo, all is well:
$ cd ~
$ mkdir poodle
$ echo "noodle" > poodle/bottle
$ cat poodle/bottle
noodle
Thoughts?
The echo command is being run as root, but the redirection is done by your shell, so it's executed as the current user, not as root.
The simplest solution is to invoke a root shell to run both the command and the redirection.
Rather than:
sudo echo line > file
try this:
sudo sh -c 'echo line > file'
or
sudo bash -c 'echo line > file'
The answer is to use "tee" with a pipe, a command I wasn't familiar with, so you can use sudo for the second half:
$ echo "tweedle ALL=(ALL) ALL" | sudo tee /etc/sudoers.d/tweedle

Resources