0

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...

  • `No such file or directory` is not a permissions or ownership error. It means that the program is not found in the `PATH`. Apparently the value of `PATH` is different when you access the shell in these different ways. Most likely you're setting the `PATH` in interactive shells only and when you use a non-interactive shell, it's not set. See the manual for your shell and read carefully the section about when the different shell setup files are parsed. – MadScientist Jun 26 '22 at 12:57
  • Hi, i have already tried to set up a new PATH because other python modules were crashing. It resolved other modules crashes but not yapf –  Jun 26 '22 at 16:26
  • OK, so whatever change you made wasn't enough to get yapf to work. You'll have to figure out why. Find out what directory `yapf` is in (e.g., `command -v yapf`). Add an `echo $PATH` to the various commands that work and don't work, to see what directories are on the PATH in each case. Then figure out how to ensure the PATH is set correctly in the places where it isn't. – MadScientist Jun 26 '22 at 16:41
  • Actually the error output was slightly different, it's about permission and not inexistence of the command since i ve put export Path and it solved this –  Jun 26 '22 at 16:52
  • To run a program you need read and execute (not write) permissions to the program and to all the directories in the path to the program. You'll have to examine this, there's nothing we can do to help since we have no idea what your environment is like. And, whatever the `#!` command is for the scripts `pylint` and `yapf` (if it's a script) need to exist and have correct permissions as well. – MadScientist Jun 26 '22 at 18:38
  • it's not a script it's a pip package! they run well when i log manually but they do not work when i use my script... –  Jun 26 '22 at 19:05
  • It has to be a program or script if you're running it from the command line like that. If it was just a python module and nothing else, you'd have to run `python ... yapf ...` not just `yapf`. Anyway, you need to give more details. Show the makefile rule that's failing. If you add into your script the direct invocation of `yapf` rather than using make, does it fail? If so it's not related to make so you should simplify by debugging that. I don't see why sudo would be involved since you are not running these commands via sudo. Use `ls` to view the permissions and see that they're right. – MadScientist Jun 26 '22 at 19:16
  • thanks for the advice. it's not failing when i dont do make format or make lint –  Jun 26 '22 at 19:20

0 Answers0