Building a plugin and I am stuck at the executing a shell command, which makes no sense why is not working

    • Resolved
    • Building a plugin and I am stuck at the executing a shell command, which makes no sense why is not working

      New

      Been banging my head trying to understand how building a plugin works, and I tell you is hard and that is because the documentation is old and not relevant anymore.

      Now I finally managed to get to the point where i actually need to execute some shell commands from the rpc file, yet the command that works well in cli refuses to be executed by rpc.

      So to give an example:

      I have a script in ~/scripts/myscript.sh
      This script has a method in it names runTest that accepts one argument.

      Running this command from terminal like this and works:

      source ~/scripts/myscript.sh && runtTest "blabla"

      Now if I try to run this command from rpc with the following code:

      $cmd = 'source ~/scripts/myscript.sh && runtTest "blabla"';
      $process = new \OMV\System\Process($cmd);
      $process->execute();But every darn time I get this error: Failed to execute command 'export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin; export LANG=C; source ~/scripts/myscript.sh && runtTest "blabla"' with exit code '127':



      Any suggestions ?
      Check out my OMV THEME CHANGER
      I do't do support on private, except for theme changer related issues.
    • New

      Virgil.A wrote:

      because the documentation is old and not relevant anymore.
      What documenation are you looking at? This guide should still work for most things - github.com/skyajal/diypluginguide3.x

      Virgil.A wrote:

      $cmd = 'source ~/scripts/myscript.sh && runtTest "blabla"';
      This isn't really a command and the tilda is telling it to use the executing user's home directory. I assume the script is in your home directory. You should always use a full path. And you should change your script to take arguments.
      omv 4.1.17 arrakis | 64 bit | 4.15 proxmox kernel | omvextrasorg 4.1.13
      omv-extras.org plugins source code and issue tracker - github

      Please read this before posting a question and this and this for docker questions.
      Please don't PM for support... Too many PMs!
    • New

      ryecoaaron wrote:

      What documenation are you looking at? This guide should still work for most things - github.com/skyajal/diypluginguide3.x
      Was talking about this one DIY Plugin Development

      Didn't know about the other one as this is the one always first in all searches :))

      As for the ~ it is used for the root directory.

      I wanted to reuse some scripts that I already use and they have more than one method in them, but I expected to be able to execute scripts the same way I execute them in the terminal this is the part I don't get, terminal command works fine rpc command returns error...
      Check out my OMV THEME CHANGER
      I do't do support on private, except for theme changer related issues.
    • New

      Virgil.A wrote:

      Was talking about this one DIY Plugin Development
      Yep that is ancient. I will have you added to the dev forum. Then your search might turn up newer info :)

      Virgil.A wrote:

      As for the ~ it is used for the root directory.
      That would assume the script is being executed by the root user. If a command is executed with sudo, it won't resolve to /root/.

      Virgil.A wrote:

      I wanted to reuse some scripts that I already use and they have more than one method in them, but I expected to be able to execute scripts the same way I execute them in the terminal this is the part I don't get, terminal command works fine rpc command returns error...
      Normally, you can but sourcing does weird things and I would try to avoid multiple commands. Your user (or the root user) might have a different profile than the user executing the code.
      omv 4.1.17 arrakis | 64 bit | 4.15 proxmox kernel | omvextrasorg 4.1.13
      omv-extras.org plugins source code and issue tracker - github

      Please read this before posting a question and this and this for docker questions.
      Please don't PM for support... Too many PMs!
    • New

      Well I managed to make any script work, it just took me a bit to realise how to make it work.

      Step 1, In your mkconf make a script file (my_script):

      Shell-Script

      1. #!/bin/sh
      2. set -e
      3. VARIABLE_NAME=$1
      4. . /etc/default/openmediavault
      5. . /usr/share/openmediavault/scripts/helper-functions
      6. source /root/scripts/myscript.sh && runtTest VARIABLE_NAME
      7. exit 0
      Display All



      Step 2 make script executable

      Source Code

      1. chmod +x my_script

      Step 3 run script from your rpc


      Source Code

      1. $cmd = new \OMV\System\Process("omv-mkconf", "my_script", escapeshellarg($params['argument_to_pass']) );
      2. $cmd->setRedirect2to1();
      3. $cmd->execute();

      Works like a charm :)) no I just created the first part of my theme changing plugin using the already built tool, so you can run it either via ssh or via the admin gui.

      If user are interested I can make some time and update the current tutorial on the forum on how to build a basic example plugin.
      Check out my OMV THEME CHANGER
      I do't do support on private, except for theme changer related issues.