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...
Related
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
OS: Ubunutu 14.04
In the /home/ubuntu directory, I created the following script:
echo >000-default.conf.test
sudo cp 000-default.conf.test /etc/apache2/sites-enabled/000-default.conf.test
sudo echo 'this is a test'>> /etc/apache2/sites-enabled/000-default.conf.test
sudo cat /etc/apache2/sites-enabled/000-default.conf.test
When I run the script, I get the following error message:
./test_f.sh: line 3: /etc/apache2/sites-enabled/000-default.conf.test: Permission denied
Any ideas why I am getting the error message when the copy operation is succeeding?
Sure.
Redirecting output into files is done by the shell, not by sudo. So if the shell is running under unprivileged user, then >> is invoked earlier than privileges are acquired by sudo.
You can use the following approach:
echo >000-default.conf.test
sudo cp 000-default.conf.test /etc/apache2/sites-enabled/000-default.conf.test
echo 'this is a test' | sudo tee -a /etc/apache2/sites-enabled/000-default.conf.test >/dev/null
sudo cat /etc/apache2/sites-enabled/000-default.conf.test
By the way, instead of
echo >000-default.conf.test
you can use
touch 000-default.conf.test
or even
>000-default.conf.test
I installed docker-compose by following the official documentation: http://docs.docker.com/compose/install/
Now I want to uninstall docker-compose.
$ docker-compose -h
offers no command for uninstalling, nor does the official documentation offer any instructions.
I deleted my docker-compose.yml file and /usr/local/bin/docker-compose, but I want to make sure that's everything.
I'm using OSX Yosemite 10.10.3 on a MacbookPro.
EDIT: Regarding the installation instructions I followed, I didn't use pip. I used the documented curl command:
$ curl -L https://github.com/docker/compose/releases/download/1.3.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
$ chmod +x /usr/local/bin/docker-compose
Documenation
Please note that this is now in the docs.
Coupled Installation and Removal
Note: on Mac Docker now installs Docker Compose. So the strategy for removal has changed a bit. If you uninstall Docker, and you want to uninstall both, then you also uninstall Docker Compose.
Individual Removal if Installed Using curl
It is commonly installed to /usr/local/bin/docker-compose on macs. However, you can run which docker-compose to find the exact location.
Run the following command (*nix systems) to remove:
rm $(which docker-compose)
If you get a permission denied error then you will need to prepend sudo:
sudo rm $(which docker-compose)
To verify that it was successful, run the following command which should return nothing:
which docker-compose
It should say that the command wasn't found.
Individual Removal if Installed Using PIP
If you've installed Docker Compose using PIP then you can run:
pip uninstall docker-compose
You may have to use sudo if you get a permission denied error:
sudo pip uninstall docker-compose
first get docker path by:
which docker-compose
then it will return path like:/usr/bin/docker-compose
then remove it:
sudo rm -rf /usr/bin/docker-compose
Nowadays docker-compose is part of the docker toolbox.
If you want to remove everything that comes with the Docker Toolbox (including Docker itself).
You can execute this shell script:
#!/bin/bash
# Uninstall Script
if [ "${USER}" != "root" ]; then
echo "$0 must be run as root!"
exit 2
fi
while true; do
read -p "Remove all Docker Machine VMs? (Y/N): " yn
case $yn in
[Yy]* ) docker-machine rm -f $(docker-machine ls -q); break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no."; exit 1;;
esac
done
echo "Removing Applications..."
rm -rf /Applications/Docker
echo "Removing docker binaries..."
rm -f /usr/local/bin/docker
rm -f /usr/local/bin/docker-machine
rm -r /usr/local/bin/docker-machine-driver*
rm -f /usr/local/bin/docker-compose
echo "Removing boot2docker.iso"
rm -rf /usr/local/share/boot2docker
echo "All Done!"
If you still have the depreciated Boot2docker and you want to get rid of it as well.
You can uninstall it by executing the following shell script:
#!/bin/bash
# Uninstall Script
if [ "$(which boot2docker)" == "" ]; then
echo "boot2docker does not exist on your machine!"
exit 1
fi
if [ "${USER}" != "root" ]; then
echo "$0 must be run as root!"
exit 2
fi
echo "Stopping boot2docker processes..."
boot2docker stop && boot2docker delete
echo "Removing boot2docker executable..."
rm -f /usr/local/bin/boot2docker
echo "Removing boot2docker ISO and socket files..."
rm -rf ~/.boot2docker
rm -rf /usr/local/share/boot2docker
echo "Removing boot2docker SSH keys..."
rm -f ~/.ssh/id_boot2docker*
echo "Removing boot2docker OSX files..."
rm -f /private/var/db/receipts/io.boot2docker.*
rm -f /private/var/db/receipts/io.boot2dockeriso.*
echo "Removing Docker executable..."
rm -f /usr/local/bin/docker
echo "All Done!"
You can also just:
sudo yum remove docker-compose-plugin
on RPM-based like Centos
according to: https://docs.docker.com/compose/install/uninstall/
I would use pip uninstall docker-compose
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 -)"
Running the command
curl -s https://www.parse.com/downloads/cloud_code/installer.sh | sudo /bin/bash
does not install the tool
I was able to install it easily on my other computer running 10.9.2
STEP : 1
Make a copy of this
#!/bin/bash
TMP_FILE=/tmp/parse.tmp
if [ -e /tmp/parse.tmp ]; then
echo "Cleaning up from previous install failure"
rm -f /tmp/parse.tmp
fi
echo "Fetching latest version ..."
curl --progress-bar https://www.parse.com/downloads/cloud_code/parse -o /tmp/parse.tmp
if [ ! -d /usr/local/bin ]; then
echo "Making /usr/local/bin"
mkdir -p /usr/local/bin
fi
echo "Installing ..."
mv /tmp/parse.tmp /usr/local/bin/parse
chmod 755 /usr/local/bin/parse `
to a file named install.sh and run it in your terminal as bash install.sh. This will install you parse in your Terminal.
STEP :2
Download the Gist from this link and run the file named install.sh in your Terminal preceded by bash