bash script not works with external commands

Hello everyone. 
when I run bash script from external commands nothing happens.

Script to turn on the printer
#!/bin/bash
if [ ! -d /sys/class/gpio/gpio17 ]
then
  echo "17" > /sys/class/gpio/export
  sleep 1;
fi
echo "out" > /sys/class/gpio/gpio17/direction
echo "1" > /sys/class/gpio/gpio17/value
When I run it from console it works.
In extcommands.xml 
<execute>/var/lib/Repetier-Server/database/turnOnPrinter.sh</execute>
I added /bin/bash to sudoers.d
# echo "repetierserver ALL=NOPASSWD: /bin/bash" > /etc/sudoers.d/repetierserver-bash
When I run external command nothing happens. Log says
Starting external command /var/lib/Repetier-Server/database/turnOnPrinter.sh with 0 parameters.
Tried
<execute>sudo /var/lib/Repetier-Server/database/turnOnPrinter.sh</execute>
with same result.

Thank you for help.

Comments

  • Did your echo create the file? # is a comment so not sure you entered it or not.
    You are not starting /bin/bash but you start /var/lib/Repetier-Server/database/turnOnPrinter.sh so that should be executable.

    echo "repetierserver ALL=NOPASSWD: /var/lib/Repetier-Server/database/turnOnPrinter.sh
    " > /etc/sudoers.d/repetierserver-turnon

    Then the version with sudo. But remember to restart server before testing or it will not use the sudo version.
  • pi@raspberrypi:~ $  sudo -u repetierserver /var/lib/Repetier-Server/database/turnOnPrinter.sh
    /var/lib/Repetier-Server/database/turnOnPrinter.sh: line 5: /sys/class/gpio/export: Permission denied
    /var/lib/Repetier-Server/database/turnOnPrinter.sh: line 8: /sys/class/gpio/gpio17/direction: Permission denied
    /var/lib/Repetier-Server/database/turnOnPrinter.sh: line 9: /sys/class/gpio/gpio17/value: Permission denied

    The cure is
    usermod -a -G gpio repetierserver


  • Ok, also a good solution. Even better because it does not require root permissions to execute the script.
Sign In or Register to comment.