External command not working with script and relay board

Dear all,

I am trying to set up external command to power on/off my printer. When I execute the script in putty, everything is working fine and as expected.

The buttons are displayed in the settings menu but it is not working.

I will really appreciate some help on this.

Scripts

relay_01_on.sh
#!/bin/bash
gpio mode 0 out
gpio write 0 0

relay_01_off.sh:
#!/bin/bash
gpio mode 0 out
gpio write 0 1

extcommands

<command>
        <name>Power ON Anycubic Kossel Linear Plus</name>
        <execute>bash /home/pi/scripts/relay_01_on.sh </execute>
        <confirm> Turn ON Anycubic Kossel Linear Plus</confirm>
    </command>
    <command>
        <name>Power OFF Anycubic Kossel Linear Plus</name>
        <execute>bash /home/pi/scripts/relay_01_off.sh </execute>
        <confirm> Turn OFF Anycubic Kossel Linear Plus</confirm>
    </command>

Comments

  • Scripts get executed as user repetierserver from Server while you are testing as user pi. Reason is normally that repetierserver is not allowed to execute that script. Copy it best to /var/lib/Repetier-Server/scripts and set permissions
    chmod 755 filename
    so everybody can execute them. Adjust path in extcommands.xml and restart server.
  • edited December 2019
    Hi, 

    I am probably doing something wrong but I cannot get these scripts working. I am not an expert and collected all the info from google.

    Step 1: copy scripts to /var/lib/Repetier-Server/scripts
              --> scripts are .sh file
    Step 2: set permission
               pi@Repetier-Server:/var/lib/Repetier-Server/scripts $ chmod 755 relay_01_on.sh
               pi@Repetier-Server:/var/lib/Repetier-Server/scripts $ chmod 755 relay_01_off.sh 

    Step 3: update extcommands file

    <command>
            <name>Power ON Anycubic Kossel Linear Plus</name>
            <execute>bash /var/lib/Repetier-Server/scripts/relay_01_on.sh </execute>
            <confirm> Turn ON Anycubic Kossel Linear Plus</confirm>
        </command>
        <command>
            <name>Power OFF Anycubic Kossel Linear Plus</name>
            <execute>bash /var/lib/Repetier-Server/scripts/relay_01_off.sh </execute>
            <confirm> Turn OFF Anycubic Kossel Linear Plus</confirm>
        </command>

    What am I missing ?
  • DO not start with bash directly. For scripts just add as first line
    #!/bin/bash

    and linux knows that script needs to be started with bash. Then omit bash parameter.
    Then try running it as user repeteirserver
    sudo -u repetierserver /var/lib/Repetier-Server/scripts/relay_01_on.sh
    
    That should show if it works and if not show error messages so you know why.
  • edited December 2019
    When a I run the command, I get this message: "No such file or directory"

    I am probably doing something wrong again.

    I confirm that both files are in the correct folder and I double checked the spelling as well. See the printscreen

    Can you confirm that both script file extcommands file are correct ?

    extcommands file:

    </command>
    <command>
            <name>Power ON Anycubic Kossel Linear Plus</name>
            <execute>#!/bin/bash /var/lib/Repetier-Server/scripts/relay_01_on.sh </execute>
            <confirm> Turn ON Anycubic Kossel Linear Plus</confirm>
        </command>
        <command>
            <name>Power OFF Anycubic Kossel Linear Plus</name>
            <execute>#!/bin/bash /var/lib/Repetier-Server/scripts/relay_01_off.sh </execute>
            <confirm> Turn OFF Anycubic Kossel Linear Plus</confirm>
        </command>






  • You missunderstood me.
    #!/bin/bash
    should be first line in your shell scripts to mark them to be executed with bash.
    In extcommands it should be
    <execute>/var/lib/Repetier-Server/scripts/relay_01_on.sh </execute>

  • edited December 2019
    I have tried this one with the same results.

    Still having this "No such file or directory" message and nothing happens when I try to run the script from the console
  • You mean running
    sudo -u repetierserver /var/lib/Repetier-Server/scripts/relay_01_on.sh

    shows the error message? In that case does 
    /var/lib/Repetier-Server/scripts/relay_01_on.sh
    work?

    If it works as pi then the path is not readable by repetierserver. Check all directory and file permissions with 
    ls -l folder
    Especially
    ls -l /var/lib/Repetier-Server
    and
    ls -l /var/lib/Repetier-Server/scripts

    Also please show output of
    cat /var/lib/Repetier-Server/scripts/relay_01_on.sh

    to see if you modified it as required.

  • edited December 2019
    Here we go:

    1. 
    pi@Repetier-Server:~ $ sudo -u repetierserver /var/lib/Repetier-Server/scripts/relay_01_on.sh
    : No such file or directory

    pi@Repetier-Server:~ $ /var/lib/Repetier-Server/scripts/relay_01_on.sh
    : No such file or directory

    2. 
    pi@Repetier-Server:~ $ ls -l folder
    ls: cannot access 'folder': No such file or directory

    3. 
    pi@Repetier-Server:~ $ ls -l /var/lib/Repetier-Server
    total 40
    drwxrwxrwx 2 repetierserver dialout 4096 Dec  6 17:44 configs
    drwxrwxrwx 2 repetierserver dialout 4096 Dec  7 18:23 database
    drwxr-x--- 2 repetierserver dialout 4096 Jun 22  2018 licenses
    drwxrwxrwx 2 repetierserver dialout 4096 Nov 24 15:58 logs
    drwxr-x--- 2 repetierserver dialout 4096 Feb  1  2019 lua
    drwxrwxrwx 3 repetierserver dialout 4096 Dec  5 17:38 printer
    drwxr-x--- 2 repetierserver dialout 4096 Jun 22  2018 projects
    drwxr-x--- 2 repetierserver dialout 4096 Nov 10 10:41 reports
    drwxr-xr-x 2 repetierserver root    4096 Dec  6 16:11 scripts
    drwxrwxrwx 2 repetierserver dialout 4096 Jul 27 09:13 tmp

    4. 
    pi@Repetier-Server:~ $ ls -l /var/lib/Repetier-Server/scripts
    total 16
    -rwxr-xr-x 1 repetierserver root 194 Mar 29  2018 mountflash
    -rwxr-xr-x 1 repetierserver pi    47 Dec  6 16:11 relay_01_off.sh
    -rwxr-xr-x 1 repetierserver pi    47 Dec  6 16:11 relay_01_on.sh
    -rwxr-xr-x 1 repetierserver root  52 Jun 26  2016 unmountflash

    5.
    pi@Repetier-Server:~ $ cat /var/lib/Repetier-Server/scripts/relay_01_on.sh
    #!/bin/bash
    gpio mode 24 out
    gpio write 24 0
  • Where is the gpio command stored? Currently I think the script is run and then gpio is the command that is not been found from the error message.

    type gpio

    should show it somewhere reachable in path variable since you did not enter full path to the command.
  • pi@Repetier-Server:~ $ gpio
    gpio: At your service!
      Type: gpio -h for full details and
            gpio readall for a quick printout of your connector details

  • But where is gpio installed? Therefore

    type gpio

    If it is in your home directory the script will not find it.

    The strange thing is when I test a command that does not exist I get:

    pi@Felix:~ $ sudo -u repetierserver ./test.shdd

    sudo: ./test.shdd: command not found

    While you get
    : No such file or directory

    The fact that you can cat the file you can not start also shows that it is there and permissions are correct. So it must be in the file but I don't see it. Have double checked and on my pi at bash is in /bin/bash - if not that line would not work and maybe cause the problem. So for safety what does

    type bash

    return and what linux are you using? From output I thought it was our pi server image in some version.

  • edited December 2019
    Wiringpi is installed in home/pi.

    I purged the install. Where am I supposed to install it and how to proceed ?
  • I also found the gpio folder located here: / sys / class / gpio

    I saw different ways to install gpio in this article. This is a bit cleared but I need to know the best method to install and where to export gpio.
  • All you need is
    sudo apt-get install wiringpi

    to install it globally like described here: http://wiringpi.com/download-and-install/
    No need to build from sources. After that it is installed in /usr/bin and available for all users.
  • I made a fresh install with the same results:


    pi@Repetier-Server:~ $ type gpio
    gpio is hashed (/usr/bin/gpio)
    pi@Repetier-Server:~ $ type bash
    bash is /bin/bash

    Here is the step by step that I have followed:

    1. Flash SD card with Etcher (Repetier-Server-Image_0_93_0_v20) + insert pro license
    2. Install wiringpi (sudo apt-get install wiringpi)
    3. Run sudo apt-get update & sudo apt-get upgrade
    4. Copy the following bash scripts (/var/lib/Repetier-Server/scripts) and set permission
    a) I have had to run the following cmd to be allowed to copy in that folder (sudo chown -R pi /var/lib/Repetier-Server)

    Copied with Filezilla

    e.g.: filename: relay_01_on.sh
    #!/bin/bash 
    gpio mode 24 out
    gpio write 24 0

    b) set permission

    pi@Repetier-Server:/var/lib/Repetier-Server/scripts $ sudo chmod 755 relay_01_on.sh
    pi@Repetier-Server:/var/lib/Repetier-Server/scripts $ sudo chmod 755 relay_01_off.sh

    5) Delete and re upload extcommand file 

    <config>
    <!--
           If you want to run external commands, enter them in this configuration with
           full path. You will see them in the main menu. Copy this file into the
           <storage>/database directory.

           Security consideration: The reason there is no online editor for this is simply
           security. The commands you enter here are executed with the privileges of the
           daemon running the server. If you would allow online configuration, a hacker could
           simply add any command he needs to hack your system.
        -->
    <command>
    <name>Shutdown Server</name>
    <execute>sudo /sbin/shutdown -h now</execute>
    <confirm>Really shut down the server?</confirm>
    <!-- Define if command should show up in local printer interface, default true.-->
    <local>true</local>
    <!-- Define if command should show up in remote printer interface, default true.-->
    <remote>true</remote>
    <!-- Define if command should show up only for users with print permission, default true.-->
    <print-permission>true</print-permission>
    <!-- Define if command should show up only for users with add files permission, default false.-->
    <add-permission>true</add-permission>
    <!-- Define if command should show up only for users with del files permission, default false.-->
    <del-permission>true</del-permission>
    <!-- Define if command should show up only for users with configuration permission, default false.-->
    <config-permission>true</config-permission>
    </command>
    <command>
    <name>Reboot Server</name>
    <execute>sudo /sbin/shutdown -r now</execute>
    <confirm>Really reboot the server?</confirm>
                    <!-- Define if command should show up in local printer interface, default true.-->
                    <local>true</local>
                    <!-- Define if command should show up in remote printer interface, default true.-->
                    <remote>true</remote>
                    <!-- Define if command should show up only for users with print permission, default true.-->
                    <print-permission>true</print-permission>
                    <!-- Define if command should show up only for users with add files permission, default false.-->
                    <add-permission>true</add-permission>
                    <!-- Define if command should show up only for users with del files permission, default false.-->
                    <del-permission>true</del-permission>
                    <!-- Define if command should show up only for users with configuration permission, default false.-->
                    <config-permission>true</config-permission>
    </command>
    <command>
            <name>Power ON Anycubic Kossel Linear Plus</name>
            <execute>/var/lib/Repetier-Server/scripts/relay_01_on.sh</execute>
            <confirm> Turn ON Anycubic Kossel Linear Plus</confirm>
        </command>
        <command>
            <name>Power OFF Anycubic Kossel Linear Plus</name>
            <execute>/var/lib/Repetier-Server/scripts/relay_01_off.sh</execute>
            <confirm> Turn OFF Anycubic Kossel Linear Plus</confirm>
        </command>
    </config>

    6) serve reboot + power off / power on

    I am probably doing something wrong somewhere in the process but for now I am still not able to run this script.
  • Arghh. You did use a windows editor and did not change line ending to unix format!
    Not you #/bin/bash ends with cr lf which does not work. You need the file in unix text format anding only with lf.

    Best is to delete the file and create it with
    nano scriptname.sh
    on the ssh console. Then it has correct line ending.
  • I have created the script with the nano command and placed it in /var/lib/Repetier-Server/scripts

    Still getting the same results.

    This is the lines that I inserted when using nano cmd

    #!/bin/bash 
    gpio mode 24 out
    gpio write 24 1

    Did I miss something ?
  • Alright, I found the issue.

    I have had to re set permissions.

    I confirm that it is working now.

    Thanks a lot for your help
  • Alright, I found the issue.

    I have had to re set permissions.

    permissions for the scripts or the folder scripts?

  • script I guess. He deleted old file to recreate it, so he lost the execute bit flag in permissions.
Sign In or Register to comment.